Tagged: Code block, filter, quick css
-
AuthorPosts
-
May 13, 2015 at 4:57 am #443513
Love the idea of the Code Block to add CSS to particular page. To me, far easier than using the page-id bit in Quick CSS.
However, I notice that sometimes, even when I put CSS at the end of a Code Block, at the end of a Page, it doesn’t affect what I want to affect.
However, that same CSS at the end of Quick CSS DOES effect changes.
Can you tell me in what situations this is true?
Is there a workaround to continue to use this CSS in Code Block instead?
Have tried putting #top in front of the CSS, but that doesn’t always do the trick.
Any ideas?
Thanks in advance for your insights.
May 13, 2015 at 9:26 am #443648Hi!
Code block should work most of the times, the thing is as it is part of the post content it may be affected by filters made by WordPress, the theme and/or external plugins.
A more reliable and modular way to add custom CSS would be to use a hook, like wp_head(+ is_page()):
add_action('wp_head', function() { if(is_page("12")){ ?> <style> .custom_css{ color: red; } </style> <?php } if(is_page("24")){ ?> <style> .custom_css{ color: red; } </style> <?php } if(is_page("48")){ ?> <style> .custom_css{ color: red; } </style> <?php } });
Cheers!
JosueMay 13, 2015 at 4:51 pm #443830Thank you, Josue!
Very clear and understandable explanation.
I shall use this, instead — or at least when I have problems “seeing” the change.
Appreciate your passing on your understanding.
One more question, though…IF it works in codeblock, wouldn’t that require less page time loading than putting LOTS of is_page code in the head?
It would be just ONE clump of CSS in codeblock versus lots of conditional stuff?May 14, 2015 at 9:01 am #444146Hey!
Yes, it may represent a higher workload if you have tons of conditionals in your functions.php, however you can always cache your website when you’re done with it.
Best regards,
JosueMay 14, 2015 at 3:23 pm #444330Thank you for the info…yes, I cache already.
Note that Enfold consistently suggests SuperCache instead of Total Cache. Is this cuz it’s easier to set up or because you think it truly is more effective?
May 14, 2015 at 7:13 pm #444540Hi,
They’re both effective, it just that W3 Total Cache may be an overkill for some users that don’t need all those features so WP Super Cache would be a better option for them.
Regards,
JosueMay 14, 2015 at 8:06 pm #444569Thank you for your quick and complete answer.
Feel free to close this.
-
AuthorPosts
- The topic ‘Quick CSS versus Code Block’ is closed to new replies.