Reputation: 654
Have implemented a site in wordpress with 5 static pages besides the usual blog pages that are accesible through the nav menu. Now each of the page has its own jquery animations.
Since I want to write the animations code for all pages in a single file I want to get the page name in javascript and then switch to the proper animation function for that page. How to do this?
Upvotes: 0
Views: 105
Reputation: 3274
If you have access to your Wordpress template, you may output the current page's ID with the the_ID()
template function: http://codex.wordpress.org/Function_Reference/the_ID
If you put this in your <head>, you could access the page ID in JavaScript afterwards:
<script>
var pageId = <?php the_ID(); ?>;
</script>
An alternative: The default theme Twenty Ten assigns a class "page-id-xx" to the <body> element by default. If your current theme does something similar, you could look for this class like this:
if ($('body').hasClass('page-id-xx')) { ... }
Upvotes: 1
Reputation: 3137
Use alert( document.URL ); it will tell you current url . and according to ypur requirement you can made changes.
see here
Upvotes: 0