Site logo

Archived topic

Change logo URL for specific pages

7 replies · Started by Elizabeth on June 17, 2020

Viewing posts 1–8 of 8

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.

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!
Liza

That's a neat conditional tag!

Glad you've figured out :)

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
};

Awesome find!

Thanks for letting me know :)

You're welcome! I appreciate the help and knowledge from the amazing people at GeneratePress!

Glad we've been helpful :)

This archived topic is closed to new replies.