store simple data in get_option()

I am trying to store simple data, a few links inside wp_options. Basically using the following way: update_option( 'simple_links', '<a href="">link 1</a>' );

my question is if it is allowed, I dont want to create new table for it, just a few links permanently stored inside the footer. Is that the valid way and will it actually save data inside options? Or there is any other better way for such a simple need?

Read More

Thank you.

Related posts

Leave a Reply

1 comment

  1. To recap the comment chain above:

    I think that’s a perfectly valid way of storing some options in the database, however, it’s good practice to prepend your option name with some unique characters pertaining to your site or something, like 'my_simple_links' to avoid possible collisions with other plugins and themes that add_options.

    Also, if you’re going to have multiple links they could be stored as an array inside one option by passing the array as the second argument (serialization will be performed automatically).

    Accessing them from your theme would be as easy as:

    <?php
        $my_simple_links = get_option( 'my_simple_links' );
        foreach ($my_simple_links  as $link )
            echo $link;
    ?>
    

    Better yet store them in an associative array as title => url and do this:

    <?php
        $my_simple_links = get_option( 'my_simple_links' );
        foreach ( $my_simple_links as $title => $url )
            echo '<a href="'.$url.'">'.$title.'</a>';
    ?>
    

    And don’t forget to read the Codex on: