Archived topic
Option for adding a custom page in Display Location Rules
11 replies · Started by Carsten on January 13, 2021
Hi there, I really like the possibilities of Elements, especially the ability to hook a non-menu item element, like different icons on different pages, but there is a limitation in relation to BuddyPress pages.
The limitation is in the Display Location Rules, because there are no option for adding a custom page like /members/me/profile/edit/, like you can add a custom hook.
Would it be possible to add this feature in the future?
Regards
Hi there,
The filter solution should be what you are looking for:
https://docs.generatepress.com/article/generate_hook_element_display/
It should handle any conditional display as long as there is a logic behind it.
Hi there, thanks for coming up with a solution to my problem, it sounds promising. I need to understand the term of a parent page.
Here are two examples of pages where I want the hook element to display, but they are not parent pages?
domain/members/me/profile/change-avatar/
domain/members/me/profile/change-cover-image/
The code then should be added to my functions.php, not inside the element itself?
Thanks!
I'm not very familiar with BuddyPress but did find all of their conditional tags here:
https://codex.buddypress.org/developer/template-tag-reference/
You will need to go through the page and try to find the conditional tags that meet your requirements.
Once you find that, just replace is_author( 'Tom' ) in the first example with the desired conditional tags.
Hi there, this sound like a promising solution, and I think I have found the right conditional tag, bp_is_profile_edit() and the id of the element is 45256
But this code pasted into functions.php breaks my site, can't see any syntax errors, so what can be wrong?
add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
if ( 45256 === $element_id && bp_is_profile_edit() ) {
$display = true;
}
return $display;
}, 10, 2 );
Thanks!
That code doesn't have any syntax errors from what I can see.
I tested using Code Snippets without any issues:
https://www.screencast.com/t/Co9ixXyZuH2k
Hi there, for some reason the conditional tag is causing this, if I change it to another tag, the site is loading again.
thanks!
Glad to hear :)
Hi there, the filter solution is working great using conditional tags for adding links to specific pages.
1. Can I add multiple tags in the same statement if ( 10 === $element_id && is_author( 'Tom' ) ) I tried separating the tags with a comma, like bp_is_activity_component(),bp_is_blogs_component() but that didn't work ;-)
2. By using the generate_hook_element_display Display Rules Location inside the element has to be empty, which leads to this:
This element needs a location set within the Display Rules tab in order to display.
What if I want to mix the filter solution and the settings for the same element?
Example, I want to display this element on my profile pages, but not on my search page
add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
if ( 45256 === $element_id && bp_is_my_profile() ) {
$display = true;
}
return $display;
}, 10, 2 );
Then I exclude the search page in the Element Display Rules, leaving the Location empty.
This leads to an error:
This element needs a location set within the Display Rules tab in order to display.
The search page is not a BP component, so it has a page id 31017.
So how do I get around this, should I then use both code examples in the generate_hook_element_display examples for the same element?
Hope my question makes sense.
Thanks!
1. Comma doesn't work in PHP. It would either be && (and) or || (or).
2. If you are using a filter then you can keep the display rules empty and set everything within the filter.
That filter you are using shouldn't display anything in the search result page.
Thanks, can the Entire site location element setting work together with an $display = false; exclusion with the same element id?
add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
if ( 45256 === $element_id && bp_is_current_component( "bp-messages" ) ) {
$display = false;
}
return $display;
}, 10, 2 );
Regards
I think that should work.
Have you tested it?