[Resolved] Change logo URL for specific pages

Home Forums Support Change logo URL for specific pages

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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.

    #1332017
    Leo
    Staff
    Customer Support

    Hi 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

    #1332602
    Elizabeth

    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

    #1332890
    Leo
    Staff
    Customer Support

    That’s a neat conditional tag!

    Glad you’ve figured out 🙂

    #1332935
    Elizabeth

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

    #1332959
    Leo
    Staff
    Customer Support

    Awesome find!

    Thanks for letting me know 🙂

    #1333056
    Elizabeth

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

    #1333084
    Leo
    Staff
    Customer Support

    Glad we’ve been helpful 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.