尝试在选定的页面上显示CSS
尝试在WordPress中选定的页面中显示某些CSS。我的标题中有以下代码。
<?php
if ( is_page('105') ) {?>
<style>.article-header {display:none;}</style>
<?php } ?>
仅当我们登录管理部分时,上面的代码工作。当我们没有登录时,该代码不起作用。
trying to display certain css in selected page in wordpress. I have below code in header.
<?php
if ( is_page('105') ) {?>
<style>.article-header {display:none;}</style>
<?php } ?>
above code work only when we are logged into admin section. The code is not working when we are not logged in. According to me it should work regardless of logging in or out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用操作钩将以下代码添加到functions.php文件中。
如果要在页脚上添加样式或脚本,则可以使用
wp_footer
挂钩,或者如果要将自定义CSS或脚本添加到标题中,则可以使用wp_head
hook。is_page()
函数有时不起作用。添加样式后,您将需要清除WordPress的缓存。
谢谢
Add the following code to functions.php file using action Hook.
if you want to add style or script on footer then you can use
wp_footer
hook or if you want to add custom css or script to header you can usewp_head
hook.is_page()
function sometime not working.after adding the style you will need to clear the cache of wordpress.
Thanks
注意:最好使用wp_add_inline_style()函数。
删除'';
示例=&gt; is_page(105)
如果未设置当前查询在网站上的现有页面设置当前查询。
在代码之前检查IS_USER_LOGGED_IN()函数。
您的代码可能写在有条件的功能中!
https://developer.wordpress.org/reference/functions/wp_add_inline_style/
Note: it's better to use the wp_add_inline_style() function.
Remove '';
example => is_page(105)
The is_page() function will return false if the current query isn't set up for an existing page on the site.
Check is_user_logged_in() function before codes.
Your code is probably written inside a conditional function!
https://developer.wordpress.org/reference/functions/wp_add_inline_style/