正文onLoad在特定的WordPress页面上 [英] body onLoad on a specific WordPress page
问题描述
我正在尝试使用最新的Wordpress版本(3.6),
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.
考虑到设置Wordpress的方式-header.php中包含body标记-如何只在特定页面的body标记中回显以上代码,而又不将其应用于其余页面?
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?>>
推荐答案
You don't need to apply the code to the <body>
tag, see: https://stackoverflow.com/a/191318/1287812
这可以在functions.php
中使用以下代码并使用SrikanthAD提及的条件标签来完成:
This can be done in functions.php
with the following code, and using the conditional tags mentioned by SrikanthAD:
add_action( 'wp_footer', 'b5f_on_load_script' );
function b5f_on_load_script()
{
// Not our page, do nothing
if( !is_page( 'about' ) )
return;
?>
<script type="text/javascript">
window.onload = function() { alert( 'Inside specific page' ); };
</script>
<?php
};
另请参阅:如何使用window.scroll在页面加载时自动滚动?
这篇关于正文onLoad在特定的WordPress页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!