[Resolved] Different Logo On Different Pages

  • Author
    Posts
  • #16571

    Andrew Misplon
    Keymaster

    Hi Karen

    If you’re targeting a post then you’ll need to change the conditional to is_single:

    https://codex.wordpress.org/Conditional_Tags#Single_Post

    is_page will work if you’re targeting a page.

    #16572

    Karen
    Participant

    Not sure why they are posts when I’ve created them as pages, but will give that a try.

    #16573

    Andrew Misplon
    Keymaster

    Please, send a link to the page concerned and I’ll take a look. Thanks.

    #16574

    Karen
    Participant

    Page Link

    I’ve got a few pages within this site that will need different logos. If I can get it working for one, pretty sure I can roll it out to the others.

    I’m not sure how to use the is_single code, sorry.

    #16575

    Andrew Misplon
    Keymaster

    Super, thanks for the link. Apologies for the hassle; I see where the issue is. I’ll get back to you ASAP tomorrow with a complete solution.

    #16576

    Karen
    Participant

    OK, sounds good. Thanks Andy.

    #16580

    Andrew Misplon
    Keymaster
    if ( ! function_exists( 'ultra_child_alt_logo' ) ) :
    function ultra_child_alt_logo( $logo_html ) {
    	if ( is_page( 24420 ) ) {
    		$logo_html = preg_replace('/<img(.*?)\/>/', '<img src="https://www.eqpartnering.co.uk/wp-content/uploads/2022/01/woodmeadow-trust.jpeg" itemprop="logo" />', $logo_html );
    	}
    
    	if ( is_page( 24421 ) ) {
    		$logo_html = preg_replace('/<img(.*?)\/>/', '<img src="https://www.eqpartnering.co.uk/wp-content/uploads/2022/01/woodmeadow-trust.jpeg" itemprop="logo" />', $logo_html );
    	}
    
    	return $logo_html;
    }
    endif;
    add_filter( 'ultra_logo_image', 'ultra_child_alt_logo' );
    #16581

    Andrew Misplon
    Keymaster

    Hi Karen

    Please, try the above. Please, copy the function directly from the forum and not from email. You can replace the IDs with your IDs and the image URLs with the required URL per page. The if conditional can be duplicated for new pages:

    if ( is_page( 24421 ) ) {
    	$logo_html = preg_replace('/<img(.*?)\/>/', '<img src="https://www.eqpartnering.co.uk/wp-content/uploads/2022/01/woodmeadow-trust.jpeg" itemprop="logo" />', $logo_html );
    }
    #16594

    Karen
    Participant

    Hi Andy,

    That worked perfectly! I can easily swop out the page IDs and image URLs and now have different logos on 3 different pages.

    Brilliant support as always. Thanks Andy 🙂

    Karen

    P.S. (Hope you don’t get this reply 3 times. Every time I click Submit, the message disappears?)

    #16607

    Andrew Misplon
    Keymaster

    Hi Karen

    Super, I’m glad to hear you’re making progress. Thanks for the update 🙂

    (bbPress put your first two replies into a pending mode for manual review. If that happens, no worries, I’ll manually approve the replies when I’m next online. I’ll delete the additional replies shortly.)

    #16610

    Karen
    Participant

    Hi Andy

    Ah ok. thanks for explaining the bbPress bit.

    Follow up question. If I have 3 pages that need one logo and 2 that need another, do I have to duplicate the conditional for each page, or can I add the other page IDs using a comma?

    Example:

    if ( is_page( 24421, 346, 123 ) ) {
    	$logo_html = preg_replace('/<img(.*?)\/>/', '<img src="https://www.eqpartnering.co.uk/wp-content/uploads/2022/01/woodmeadow-trust.jpeg" itemprop="logo" />', $logo_html );
    }
    #16611

    Andrew Misplon
    Keymaster

    “3 pages that need one logo” would go in one conditional.

    “2 that need another” would go in another conditional.

    You can use commas for multiple IDs in an array as follows:

    is_page( array( 42, 54, 6 ) )

    Examples using the is_page conditional can be found at https://developer.wordpress.org/reference/functions/is_page/. Scroll down to the bottom.

    Thanks 🙂

    #16616

    Karen
    Participant

    Brilliant. Thanks Andrew.

    #16619

    Andrew Misplon
    Keymaster

    Glad to hear you’re making progress 🙂

Viewing 14 posts - 16 through 29 (of 29 total)

The topic ‘Different Logo On Different Pages’ is closed to new replies.

Scroll to top