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.
2
Answers
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/
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