Archived topic
How do I add a custom link page as element location?
8 replies · Started by Carsten on May 4, 2020
Hi there, I want to add my BuddyPress register custom link page to a hook element.
The problem is that the Location options does not cover custom links, only pages.
So even if the register page appears among the pages, the content does not display. As reference, I tested with the entire site, where the content apply.
How do I add a custom link page as location?
Suggestion, would it be possible to add location by page id?
Thanks
Hi there,
I believe you are looking for these filters:
https://docs.generatepress.com/article/generate_header_element_display/
https://docs.generatepress.com/article/generate_hook_element_display/
Let me know if this helps :)
Hi there, thanks for the article and code.
I pasted in the element and page id's and added it to my functions.php, but it does not kick in, my content is displayed on all pages, any idea why?
add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
global $post;
if ( 34354 === $element_id && ( is_page() && $post->post_parent == '34311' ) ) {
$display = true;
}
return $display;
}, 10, 2 );
Hi there,
Is that condition correct for you? What page are you trying to target?
ID 34311 is my register page, and the one I'm trying to target, but the content is displayed on every page of the site.
I can leave the Location setting in the element to Entire Site, right?
In that case, you would:
1. Empty your Display Rules
2. Do this:
add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
global $post;
if ( 34354 === $element_id && is_page( '34311' ) ) {
$display = true;
}
return $display;
}, 10, 2 );
That's strange, the content is displaying on the wrong page, the frontpage with id 33269, how can that be possible? I have emptied cache?
Just to clarify, can location set be emty?
This element needs a location set within the Display Rules tab in order to display.
Hi there, I solved the issue by using a bp_before_register_page hook instead of page id.
Thanks for the help
Glad you got it working :)