WordPress.org

Support

Support » How-To and Troubleshooting » How to get the template path within JavasScript?

How to get the template path within JavasScript?

  • Michelle Langston

    @chellycat

    Theme Wrangler at Automattic

    On my theme I have one of those horizontal sliding carousels that displays photos. It uses 2 arrow images to slide forward and backward. I want those arrows stored in my theme folder. How would I set the paths of those images within my javascript code to match my theme folder without hard-coding it? Here’s the javascript code (abbreviated just to show the problem spot):

    stepcarousel.setup({
    leftnav: ['library/js/carousel_prev.gif', 895, -26],
    rightnav: ['library/js/carousel_next.gif', -24, -26],
    })

    As it stands, the path /library/js/carousel_prev.gif is treated as http://www.mysite.com/library/js/carousel._prev.gif

    I want the path to be http://www.mysite.com/wp-content/themes/mytheme/library/js/carousel_prev.gif

    If I insert PHP in there, it just converts it to a string.

    Help! Thanks.

    Oh and if it’s relevant, this is a jQuery script, loaded on DOM ready.

  • The topic ‘How to get the template path within JavasScript?’ is closed to new replies.