Archived topic
Exclude search results from generate_block_display_element filter
2 replies · Started by Incal on June 27, 2022
Viewing posts 1–3 of 3
Hi,
I used this code found in this forum to display a layout element only when the page has a certain custom field value.
However, now the element is also applied to the search results, and the page titles are hidden as a result.
Is there a way to exclude search results to prevent this from happening?
Many thanks,
Kevin
add_filter( 'generate_block_element_display', function( $display, $element_id ) {
global $post;
if ( 17734 === $element_id && get_field('page_type') === "review") {
$display = true;
}
return $display;
}, 10, 2 );
I found a solution by adding is_search().
Hi there,
Glad you were able to sort it out :)
This archived topic is closed to new replies.