-1

OK, that was helpful. But I need it a bit more complicated. I need a script to add a custom css to all pages, exept on one. How can I do that?

2
  • 2
    Is the question complete? I'm not sure what you're referring to when you say that was helpful, can you edit your question so it's clearer? – Tom J Nowell Mar 9 at 14:52
  • I'm so confused. – Tony Djukic Mar 10 at 4:01
1

add this to end of functions.php

function mmk_enqueue_script(){
    if( !is_page(123) ){
    wp_enqueue_style('responsive-css', get_stylesheet_directory_uri() . '/custom.css', false);
    }
    }
    add_action( 'wp_enqueue_scripts', 'mmk_enqueue_script', 999);

create a custom.css inside your theme directory. this CSS file will be applied to all pages except the one you specified.

update "123" inside if condition with page id where you don't want custom css.

The above code will enqueue additional css based on the condition. for more info https://developer.wordpress.org/reference/functions/wp_enqueue_style/ https://developer.wordpress.org/reference/functions/is_page/

2
  • This is overkill when the same can be achieved with a CSS rule alone. – Jacob Peattie Mar 10 at 7:17
  • 1
    agree, but depends on the context. if you want to style an entire page that is different from the rest of the site, a separate CSS won't hurt if it is loaded only on that specific page. – MMK Mar 10 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.