- This topic has 28 replies, 2 voices, and was last updated 2 years, 10 months ago by Andrew Misplon.
- AuthorPosts
- February 15, 2022 at 3:55 pm #16571
Andrew MisplonKeymasterHi 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.February 15, 2022 at 5:55 pm #16572
KarenParticipantNot sure why they are posts when I’ve created them as pages, but will give that a try.
February 15, 2022 at 5:57 pm #16573
Andrew MisplonKeymasterPlease, send a link to the page concerned and I’ll take a look. Thanks.
February 15, 2022 at 6:05 pm #16574
KarenParticipantI’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.
February 15, 2022 at 7:26 pm #16575
Andrew MisplonKeymasterSuper, 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.
February 15, 2022 at 7:30 pm #16576
KarenParticipantOK, sounds good. Thanks Andy.
February 16, 2022 at 8:10 pm #16580
Andrew MisplonKeymasterif ( ! 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' );
February 16, 2022 at 8:13 pm #16581
Andrew MisplonKeymasterHi 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 ); }
February 21, 2022 at 3:46 pm #16594
KarenParticipantHi 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?)
February 22, 2022 at 8:29 am #16607
Andrew MisplonKeymasterHi 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.)
February 23, 2022 at 5:36 pm #16610
KarenParticipantHi 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 ); }
February 24, 2022 at 11:27 am #16611
Andrew MisplonKeymaster“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 🙂
February 25, 2022 at 3:18 pm #16616
KarenParticipantBrilliant. Thanks Andrew.
February 25, 2022 at 6:41 pm #16619
Andrew MisplonKeymasterGlad to hear you’re making progress 🙂
- AuthorPosts
The topic ‘Different Logo On Different Pages’ is closed to new replies.