- This topic has 8 replies, 3 voices, and was last updated 5 months, 2 weeks ago by
David.
-
AuthorPosts
-
October 11, 2022 at 6:25 am #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,
JanOctober 11, 2022 at 5:42 pm #2370493Fernando 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 withaction
and399523
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.October 12, 2022 at 12:43 pm #2371520Jan
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,
JanPS: 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?October 14, 2022 at 5:23 am #2373304Jan
Hi Fernando,
any chance you can take a look into this at your next convenience?
I’d highly appreciate your view.
Thanks,
JanOctober 14, 2022 at 6:49 am #2373386David
StaffCustomer SupportHi there,
quick question – what plugin is creating that account page ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 15, 2022 at 9:05 am #2374602Jan
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,
JanOctober 16, 2022 at 4:34 am #2375065David
StaffCustomer SupportOk, 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')
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 16, 2022 at 11:36 am #2375528Jan
Great. Thanks, David.
The revised filter works very well.
Best, Jan
October 17, 2022 at 2:34 am #2375991David
StaffCustomer SupportGlad to hear that!
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.