[Resolved] Element display rule to exclude a specific path

Home Forums Support [Resolved] Element display rule to exclude a specific path

Home Forums Support Element display rule to exclude a specific path

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1250131
    Steven

    Is there a way to have an element either apply to or be excluded from a particular URL path. We’re trying to integrate BetterDocs for our internal help system in WordPress for our content editors. When we try to exclude the site header and footer from the Docs post type, it works for that particular custom post. However, it has some category and keyword custom post types as well. While we could add every category and keyword to exclude the header/footer elements, we’d have to touch this element every time we added a new category or element. It would be nice to have the display rule option of “exclude everything under /docs* on the site” or something like that. There are actually several elements we inject for our header and footer, so manually updating all of these with the category and tag display rules would be cumbersome. Happy to look at alternatives as well if there’s a better strategy.

    We haven’t made the docs private yet, so you can reproduce what we’re experiencing by going to the URL in this ticket and then selecting the “News” category. That will take you to a category page where parts of the header and footer aren’t suppressed.

    #1250999
    David
    Staff
    Customer Support

    Hi there,

    with the Display rules i would expect to see something like docs for the singles and docs archive – surely you could just exclude those two locations?

    Let me know.

    #1252229
    Steven

    I recall seeing doc archives in the settings at one time and then couldn’t find it later. I discovered there’s a setting in BetterDocs (Enable Built-in Documentation Page). If you deselect this option choose your own custom starting page for documentation (i.e. a regular WordPress page that you add shortcodes to), then the Docs Archive option disappears in the GP Elements display rules screen. Reselecting this option made the archives option available and we’re able to suppress what we need to.

    Thanks for the tip David!

    #1252769
    David
    Staff
    Customer Support

    Glad to be of help 🙂

    #2064517
    Chad

    Hi,

    I had this same question.

    In the exclude options, you can only select individual pages.

    Is there a way to exclude the Element from all pages in a path?

    ex. website.com/services; website.com/services/service-one; website.com/services/service-two; etc.

    Thanks!

    #2064760
    David
    Staff
    Customer Support

    Hi there,

    If that is for Page Parents and Children, then not from within the Display Rules.
    But you can use the generate_element_display filter:

    https://docs.generatepress.com/article/generate_element_display/

    For example this PHP Snippet:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        global $post;
        if ( 100 === $element_id && 123 == $post->post_parent ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    Will remove the element from a child of a parent post.
    The 100 needs to be changed to the ID of the Element. And the 123 the ID of the Parent post.

    #2065055
    Chad

    Thanks! That seemed to work!

    You can use the Display rules as well as that snippet to exclude other pages/sections.

    Thanks again!

    #2065060
    David
    Staff
    Customer Support

    Glad to hear that!

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