Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #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.

    #443648

    Hi!

    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!
    Josue

    #443830

    Thank 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?

    #444146

    Hey!

    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,
    Josue

    #444330

    Thank 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?

    #444540

    Hi,

    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,
    Josue

    #444569

    Thank you for your quick and complete answer.

    Feel free to close this.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Quick CSS versus Code Block’ is closed to new replies.