Hide a div based on url


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.home would be your homepage, body.page-123 would 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_class filter 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' );

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

Source link