- This topic has 11 replies, 2 voices, and was last updated 3 years, 3 months ago by Leo.
-
AuthorPosts
-
January 13, 2021 at 10:06 am #1617460Carsten
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
January 13, 2021 at 2:33 pm #1617724LeoStaffCustomer SupportHi 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.
January 13, 2021 at 2:46 pm #1617731CarstenHi 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!
January 13, 2021 at 2:59 pm #1617752LeoStaffCustomer SupportI’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.January 14, 2021 at 5:24 am #1618293CarstenHi 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 45256But 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!
January 14, 2021 at 9:55 am #1618868LeoStaffCustomer SupportThat 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/Co9ixXyZuH2kJanuary 14, 2021 at 2:45 pm #1619145CarstenHi there, for some reason the conditional tag is causing this, if I change it to another tag, the site is loading again.
thanks!
January 14, 2021 at 2:45 pm #1619146LeoStaffCustomer SupportGlad to hear ๐
January 16, 2021 at 6:15 am #1621147CarstenHi 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, likebp_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!
January 16, 2021 at 11:27 am #1621610LeoStaffCustomer Support1. 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.
January 16, 2021 at 2:14 pm #1621747CarstenThanks, 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
January 16, 2021 at 4:29 pm #1621830LeoStaffCustomer SupportI think that should work.
Have you tested it?
-
AuthorPosts
- You must be logged in to reply to this topic.