- This topic has 7 replies, 2 voices, and was last updated 8 months, 2 weeks ago by
Leo.
-
AuthorPosts
-
June 17, 2020 at 4:14 pm #1331945
Elizabeth
I’m working on a site with two specific sections – one for patients and the other for health care professionals.
When a person in on any page within the section for healthcare professionals, I need to change the site logo URL to /hcp/.
I found another support topic that looked promising (https://generatepress.com/forums/topic/change-logo-and-url-on-specific-pages/) but is more complex than I need.
The primary HCP page is https://tiglutik.candyappledev.com/hcp/ and all secondary pages are child pages to this main page. I tried modifying a filter from the support topic above, here’s my version:
add_filter( ‘generate_logo_href’, function( $url ) {
$site_url = site_url();if ( is_tree( ’16’ )) {
return $site_url . ‘/hcp/’;
}return $url; // Return the default.
}This didn’t work and triggered a critical error. Do you see what I missed or got wrong? I’m open to trying it another way if you have a different suggestion.
June 17, 2020 at 6:55 pm #1332017Leo
StaffCustomer SupportHi there,
Try this:
add_filter( 'generate_logo_href', function( $url ) { if ( is_page( array( 1, 2, 3 ) ) ) { return 'URL for HCP'; } return $url; } );
https://codex.wordpress.org/Conditional_Tags#A_PAGE_Page
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 18, 2020 at 6:25 am #1332602Elizabeth
Hi Leo,
Thank you very much, that works perfectly!
I was able to substitute is_tree into your filter since this section might grow and this will with managing the pages down the road.
add_filter( ‘generate_logo_href’, function( $url ) {
if ( is_tree( 16 ) ) {
return ‘https://tiglutik.candyappledev.com/hcp/’;
}return $url;
} );Thank you again so much!
LizaJune 18, 2020 at 8:34 am #1332890Leo
StaffCustomer SupportThat’s a neat conditional tag!
Glad you’ve figured out π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 18, 2020 at 8:52 am #1332935Elizabeth
It is a very helpful tag, especially for larger sites. It just requires this extra function:
function is_tree($pid) { // $pid = The ID of the page we’re looking for pages underneath
global $post; // load details about this page
if(is_page()&&($post->post_parent==$pid||is_page($pid)))
return true; // we’re at the page or at a sub page
else
return false; // we’re elsewhere
};June 18, 2020 at 9:03 am #1332959Leo
StaffCustomer SupportAwesome find!
Thanks for letting me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 18, 2020 at 10:37 am #1333056Elizabeth
You’re welcome! I appreciate the help and knowledge from the amazing people at GeneratePress!
June 18, 2020 at 11:04 am #1333084Leo
StaffCustomer SupportGlad we’ve been helpful π
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.