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


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.

  • 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.
    – fuxia
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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