Search code examples
phpwordpresswordpress-themingstring-concatenation

How do I concatenate a string in a PHP Array Element?


I am customizing wordpress blog and I have a need to make custom sidebar widgets. My PHP is rusty at best. What I am trying to do is concatenate a php variable into a string being set as an array element. here is the code I am using, it doesn't seem to work. All it does is print the stylesheet directory at the top of every page:

if ( function_exists("register_sidebar") )
    register_sidebar(array(
        "before_widget" => "<div class=\"rounded_box\"><div class=\"top_curve\"><img src=\"".bloginfo('stylesheet_directory')."/images/top_curve.jpg\" alt=\"Top\" width=\"247\" height=\"9\" /></div><div class=\"middle\">",
        "after_widget" => "</div><div class=\"bottom_curve\"><img src=\"".bloginfo('stylesheet_directory')."/images/bottom_curve.jpg\" alt=\"Bottom\"  /></div></div>",
        "before_title" => "<h2>",
        "after_title" => "</h2>",
    ));

so as you can see here I am trying to concatenate the bloginfo('stylesheet_directory') into 2 of the elements. This doesn't work properly. It just ends up printing it at the top of the page before the doctype.


Solution

  • bloginfo('stylesheet_directory') will echo the stylesheet directory. When you declare the array, you are effectively writing to stdout. This is why it will show on top of the page. What you are looking for is get_bloginfo.