echo is out of order - help

6 views
Skip to first unread message

shelfish

unread,
Nov 12, 2009, 1:55:52 PM11/12/09
to PHP Hacks
G'day,

Really frustrated with what should be a simple script. Using
wordpress...

************ Code ******************
function include_script ($jsFileName){

$callScript = '<script type="text/javascript" src="' . bloginfo
('template_url') . '/js/' . $jsFileName . '"></script>';

return $callScript;
}

echo(include_script('main_scripts.js') . "\n");

************ End Code ******************

********************** results ************************

http://www.domain.com/wp-content/themes/mytheme<script type="text/
javascript" src="/js/main_scripts.js"></script>

****************** End results *******************

Any help on why this might be happening would be greatly appreciated.
What am I missing?

Ahmad Saleh

unread,
Nov 13, 2009, 5:54:14 AM11/13/09
to php-...@googlegroups.com
Hi,

looks like that instead of returning the url from this function (bloginfo('template_url')) you printed it and didn't return anything.

Am I right ;) ?

ZYsoftik

unread,
Nov 14, 2009, 3:58:16 AM11/14/09
to PHP Hacks
Hi,

bloginfo *outputs* the requested parameter, but doesn't return it.
Try this:

function include_script ($jsFileName){
ob_start();
echo '<script type="text/javascript" src="';
bloginfo('template_url');
echo '/js/' . $jsFileName . '"></script>';
return ob_get_clean();
Reply all
Reply to author
Forward
0 new messages