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
    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, 2021 at 14:52
  • I'm so confused. Mar 10, 2021 at 4:01

1 Answer 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/

  • This is overkill when the same can be achieved with a CSS rule alone. Mar 10, 2021 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, 2021 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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