[Support request] Make legacy hooks apply only to certain pages

Home Forums Support [Support request] Make legacy hooks apply only to certain pages

Home Forums Support Make legacy hooks apply only to certain pages

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #822466

    Last year I built a real estate site in GeneratePress Premium and Elementor Pro that preceded Elementor’s addition of nav menus, headers, footers and the theme builder. I displayed the Elementor-created footer and top bar in GP using hooks and Elementor shortcodes, and used GP’s menu and page header.

    Now the RE company has switched to a different IDX system that creates pages outside of the WP page structure (MLS Search results, login, register, and listing detail, maybe others I haven’t found yet), that use the theme, but none of the disable/include/exclude features of either GP or Elementor work on those pages because they aren’t visible to the plugins and that’s become a problem.

    Is it possible in GP to only display the Elementor-created top bar and footer on the pages that Elementor ignores, that are outside of the WP page structure? Then I could use Theme Builder for all the standard WP pages.

    GeneratePress 2.2.2
    GP Premium 1.7.8
    Customer Support

    Hi there,

    I’m not aware of conditional tags specific to Elementor.

    But you can certainly target certain pages by doing this:

    I would also recommend migrating over to our new Hooks Element module so that you can use the display rules instead of writing conditional tags:

    Let me know if this helps 🙂


    Elementor allows one to create a template and specify what pages/posts it will be displayed on or excluded from. But that doesn’t really matter, because in order to target those pages in Elementor, or GeneratePress, the page has to actually exist in the WordPress page structure and the pages I’m dealing with are generated by the IDX plugin and not part of the site’s page structure. On a number of the IDX search pages, there’s a class applied to the body, and I used that to do a display:none on the header image, which is a hack but I’m not fluent in php so it met my need.

    However there are the detail pages which are not so generous with classes in the list of body classes so I can’t target them with css.

    What I really want to do is to remove the .pagehero element (header image and the content title) from any page whose directory path after the domain name starts with “real-estate” or “account”. I’ve been reading that I can extract the first level directory using:

    $url = explode('/', $_SERVER['REQUEST_URI']);
      $dir = $url[1] ? $url[1] : 'home';

    and that I can remove the header using

    add_action( 'after_setup_theme','tu_remove_header' );
    function tu_remove_header() {
        remove_action( 'generate_header','generate_construct_header' );

    and I suppose there must be an if statement in between but I don’t know how to construct this. Can you help?

    Lead Developer
    Lead Developer

    If that code you found works, you should be able to do this:

    add_action( 'after_setup_theme', function() {
        $url = explode('/', $_SERVER['REQUEST_URI']);
        $dir = $url[1] ? $url[1] : 'home';
        if ( 'real-estate' === $dir || 'account' === $dir ) {
            remove_action( 'generate_header','generate_construct_header' );
    } );
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.