• carbonmadex

    (@carbonmadex)


    Hello,

    I was wondering if it is possible to add a template tag like <?php bloginfo('template_url'); ?> in a script file?
    I cannot call the necessary parts of the script from the header.php so I need to insert the template tag to the script.

Viewing 3 replies - 1 through 3 (of 3 total)
  • esmi

    (@esmi)

    What kind of script?

    Thread Starter carbonmadex

    (@carbonmadex)

    A lightbox script. Which has links for flvplayer and mp3player in it like this:

    FLVPlayer:		"/js/FLVplayer.swf",   // URL of the FLV Player
    MP3Player:	"/js/MP3player.swf",  // URL of the MP3 Player

    And I need to add <?php bloginfo('template_url'); ?> to the beginning in order to generate the right URL. I cannot write it directly because it will be a template. And I cannot call this part of the script from header.php either. So I need to make the template_tag work inside the script file.

    Moderator keesiemeijer

    (@keesiemeijer)

    Put this in your theme’s functions.php:

    add_action( 'wp_head' , 'my_plugin_wp_head' );
    function my_plugin_wp_head()
    {
         print('<script type="text/javascript">var TEMPLATE_URL = "' . get_bloginfo('template_directory') . '";</script>');
    }

    and call your javascript file after the <?php wp_head(); ?> in your theme’s header.php
    Now you can use the variable TEMPLATE_URL in your script like this:

    MP3Player:	TEMPLATE_URL + "/js/MP3player.swf",  // URL of the MP3 Player

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Template tag in script file’ is closed to new replies.