Skip to content Skip to sidebar Skip to footer

Wordpress Root Url With Javascript

I am using this script on my Wordpress website: JQuery Plugin: Random Image The problem I have is that I don't know what sort of code to put in the path section so that Wordpress w

Solution 1:

You have to echo it.

<?phpecho get_bloginfo("template_url"); ?>

or you can use

<?php bloginfo("template_url"); ?>

Solution 2:

Ok, I got it working through trial and error and I will list here things that I did wrong, just in case someone else is having the same problem:

  1. I put the var templateUrl code in separate javascript tags. Later on I moved it just above $(document).ready(function() {

  2. I put templateUrl in the actual .js file. I later on moved it to: $('.shuffle').randomImage({path: templateUrl + /images/});

The end result looks like this:

<scripttype="text/javascript">var templateUrl = '<?php bloginfo('template_directory'); ?>';
    $(document).ready(function() {
        $('.shuffle').randomImage({path: templateUrl + /images/});
    });
</script>

The script is now working perfectly! Thanks to everyone for help! :)

Solution 3:

<scripttype="text/javascript">var themeFolder = '<?phpecho get_template_directory_uri(); ?>'; 
</script>

Post a Comment for "Wordpress Root Url With Javascript"