Do not apply CSS rule to just one page

Asked

Viewed 339 times

2

I have a CSS class that I would like to nay applied when I’m on a page: example.com.br/test

There’s a way I can do that with some CSS rule?

This is the class:

.section-name {
    display: none;
}
  • unfortunately no, the correct would be to create a class with a different name and apply or not when necessary.

1 answer

4

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

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

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

EDIT - WORDPRESS

As you asked for Wordpress, I will give some advice. However there is a time that does not work with Wordpress. Anyway, you can still use the technique I showed you above, only you will need a way to add the end of your url as a body on the page. In Wordpress they call it Page Slug, and you can search for plugins that do this automatically, like that.

I tried to know too, but I have no way to test at the moment, but apparently, by putting this function in the functions.php theme, 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' );
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.