Hide a div based on url
-
Hi!
I am looking for a solution where I can hide the DIV if the user is at a specific url. The content under the URL is dynamically generated.
Ideally, you could implement your solutions to your functions.php file.Thank you in advance!
Best Regards
Matthew-
This topic was modified 5 years, 7 months ago by
Mateusz Turek.
-
This topic was modified 5 years, 7 months ago by
-
Hello,
This is a difficult question to answer without either seeing the website or knowing the specifics of the URL. In theory, the main
<body>tag should have a list of generated classes assigned to it based on the current page.body.homewould be your homepage,body.page-123would be when you’re viewing page with the ID of 123. You could inspect the body tag and see if there’s any special classes you could use in your CSS selector.If not, you can use the
body_classfilter hook to test if you’re on the specific page and push a custom class to the lot:/** * Add in additional body classes * * @param Array $classes * * @return Array $classes */ function wpf13546176_body_classes( $classes ) { // If we're viewing page with ID 123 if( is_page() && is_page( 123 ) ) { /** * Will append to the body tag our class * <body class="... hide-xyz-div"> * * Hide our div in CSS * body.hide-xyz-div div.xyz { display: none; } */ $classes[] = 'hide-xyz-div'; } return $classes; } add_filter( 'body_class', 'wpf13546176_body_classes' );Hi,
I used the <body> tag to define which classes I want to exclude. It works! Thank you very much for solving my problem.Best Regards
Matthew
The topic ‘Hide a div based on url’ is closed to new replies.