[Resolved] Exclude search results from generate_block_display_element filter

Home Forums Support [Resolved] Exclude search results from generate_block_display_element filter

Home Forums Support Exclude search results from generate_block_display_element filter

  • This topic has 2 replies, 2 voices, and was last updated 2 years ago by Stacey Usborne.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2266302
    Incal

    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 );
    #2266309
    Incal

    I found a solution by adding is_search().

    #2266435
    Stacey Usborne
    Staff
    Customer Support

    Hi there,

    Glad you were able to sort it out 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.