Using the latest Wordpress version (3.6), I am trying to apply:
<body onLoad="window.scroll(0, 150)">
To a specific landing page on my website so that the page scrolls to a specific point on page load.
Given the way that Wordpress is set up - with the body tags included in header.php - how can I echo the above code within the body tag for my specific page only, without applying it to the rest of my pages?
I am presuming something needs to go in here:
<body <?php body_class(); ?><?php my code in here?>>
For some reason, I was having difficulties using the above approach, however the logic was correct.
I have now instead registered the scroll script separately and enqueued it based on page template using:
With:
window.onload=function(){window.scroll(0, 140)};
as a separate file.Thanks for all the help.
You don't need to apply the code to the
<body>
tag, see: https://stackoverflow.com/a/191318/1287812This can be done in
functions.php
with the following code, and using the conditional tags mentioned by SrikanthAD:Also see: How to use window.scroll to automatically scroll on pageload?
You can use many of the conditional tags available in WordPress to get the desired functionality.
http://codex.wordpress.org/Conditional_Tags
Example:
I agree with brasofilo, you don't necessarily have it include the conditional tag in your template. It can used anywhere, depending on your project.