WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I am making plugin default option sets.I put my code like this.Basically I want to give an image path in plugin folder.I did this .

function add_scroll_default() {
$tmp = get_option('scroll_options');
if((!is_array($tmp))) {
    $arr = array("top_image"=>"echo'plugins_url( '/image/top.png', __FILE__ )'");
    update_option('scroll_options', $arr);


Upon inspection on database I found that the value stored

echo'plugins_url( '/image/top.png', __FILE__ )'

But I want to put the image url? Thanks

share|improve this question

There are two errors in your code.

  1. "echo'plugins_url( '/image/top.png', __FILE__ )'" is not executed, it is just a string that happens to look like PHP code. What you really want is:

    $arr = array( "top_image"=> plugins_url( '/image/top.png', __FILE__ ) );
  2. Do not store default options in the database. Use the second parameter for get_option( $option, $default ); instead.

    So whenever you fetch the option, provide the default values as second argument:

    $option = get_option( 
            "top_image"=> plugins_url( '/image/top.png', __FILE__ ) 

    The reason is that you cannot rely on the stored values anyway. They might be deleted already, so you have to provide the default values always.

share|improve this answer
I don't think you want the leading slash here either: plugins_url( '/image/top.png', __FILE__ ) - try plugins_url( 'image/top.png', __FILE__ ) instead – TomC Dec 16 '13 at 4:00
@TomC Doesn’t matter, WordPress strips the left / from the path. – toscho Dec 16 '13 at 4:08
Thank you @toscho .PLease help a bit more.I followed your method to fetch option .But it output only Array.Though I found other way using php empty to check for input – ashraf Dec 16 '13 at 4:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.