[Resolved] Elements Block / Page hero / Display Rule / URL regular expression

Home Forums Support [Resolved] Elements Block / Page hero / Display Rule / URL regular expression

Home Forums Support Elements Block / Page hero / Display Rule / URL regular expression

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2369829
    Jan

    Hi there,

    I’m working on a membership site that has an account page with multiple sub-pages. All subpages have the same URL except for the action suffix at the end.

    I’d like to display different headlines on each subpage using an Elements Block/ Page hero.

    How can I set up the Display rule to achieve that?

    Thanks,
    Jan

    #2370493
    Fernando
    Customer Support

    Hi Jan,

    Set the Block element display rule location to Choose so it defaults to not display in any page.

    Then add this Snippet:

    add_filter( 'generate_block_element_display', function( $display, $element_id ) {
    	$current_url = get_permalink();
    	$url_basis = 'https://fazarcon.pluginsupportwp.com/how-one-affiliate-marketer-increased-profits-by-300-with-linkly/';
        if ( 399523 === $element_id && str_starts_with($current_url, $url_basis) ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

    Replace the url_basis with your url ending with action and 399523 with the Block Element ID.

    Basically, this code checks if the URL of the page starts with the url_basis and displays the Block Element if it does.

    #2371520
    Jan

    Hi Fernando,

    thanks for getting back.

    This is how I edited the filter:

    // GP - Add custom header to MP account subpages
    
      add_filter( 'generate_block_element_display', function( $display, $element_id ) {
        $current_url = get_permalink();
        $url_basis = 'https://seo-sharing-system.de/mitglieder/account/?action=sunscriptions';
          if ( 12029 === $element_id && str_starts_with($current_url, $url_basis) ) {
              $display = true;
          }
      
          return $display;
      }, 10, 2 );

    This is the Block Element ID (Page hero) that is required for the “subscription” URL.

    The header does not show on the relevant page ;-/

    What am I missing?

    Thanks,
    Jan

    PS: There are 4 subpages in total. All with the same base URL (but different action attribute at the end). Consequently I’ll need to add 4 different filters each pointing to the right block Element, correct?

    #2373304
    Jan

    Hi Fernando,

    any chance you can take a look into this at your next convenience?

    I’d highly appreciate your view.

    Thanks,
    Jan

    #2373386
    David
    Staff
    Customer Support

    Hi there,

    quick question – what plugin is creating that account page ?

    #2374602
    Jan

    Hi David,

    the account page belongs to the MemberPress plugin. I brought up the question with them first, asking how to display different page titles for the different subpages of the account page.

    Their recommendation was to modify the related .php template files for each subpage to achieve that same. I didn’t like this because template files may change going forward which in turn will always require me to carry out an impact analysis.

    Staying with the MP standard template files and rather injecting individual headers blocks for each subpage appear to be the more viable solution.

    Regarding the advise from Fernando: I’m not sure whether I adjusted the filter incorrectly or whether there is some more tweaking needed for the filter itself.

    Please let me know.

    Thanks,
    Jan

    #2375065
    David
    Staff
    Customer Support

    Ok, was kind of hoping they may have some endpoint function which we could use.
    Instead lets try this snippet:

    
    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 123 === $element_id && strpos($_SERVER['REQUEST_URI'], 'subscriptions') !== false ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    123 needs to match the ID.
    And this line is where we check for the URI Parameter eg. subscriptions:

    strpos($_SERVER['REQUEST_URI'], 'subscriptions')

    #2375528
    Jan

    Great. Thanks, David.

    The revised filter works very well.

    Best, Jan

    #2375991
    David
    Staff
    Customer Support

    Glad to hear that!

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