Do not apply CSS rule on only one page

2

I have a CSS class that I would like not to apply when I'm on a page: example.com/test/

How can I do this with some CSS rule?

This is the class:

.section-name {
    display: none;
}
    
asked by anonymous 15.03.2017 / 21:19

1 answer

4

You can put a unique class in the body of your page. For example, on exemplo.com.br/teste page, you could put the class: exclusive in body . Then in your CSS you put:

body:not(.exclusive) .section-name {
    display: none;
}

In this case it would be applied to all .section-name , unless that class is applied to body .

EDIT - WORDPRESS

As you asked for Wordpress, I'll give you some advice. But there is a time that I do not work with Wordpress. Anyway, you can still use the technique I showed you above, except that you will need a way to add the end of your url as a class of body of the page. In Wordpress they call it Page Slug, and you can look for plugins that do this automatically, such as this .

I tried to find out too, but I can not test it at the moment, but apparently putting this function in functions.php will have the same effect:

//Page Slug Body Class
function add_slug_body_class( $classes ) {
    global $post;
    if ( isset( $post ) ) {
        $classes[] = $post->post_type . '-' . $post->post_name;
    }
    return $classes;
    }
    add_filter( 'body_class', 'add_slug_body_class' );
}
    
15.03.2017 / 21:24