This is a short post. Simply put it’s essentially just a code snippet. I wanted to manage the site logo through the WordPress Theme Customizer in the WordPress backend administration area of a WordPress website. That way, my users can add/edit/delete images and directly see an instant update in the Theme Customizer Live Preview

WordPress Theme Display Custom Logo Without Anchor Wrapping Image

When you make a call to the_custom_logo(); in your theme, it retrieves the necessary logo image file, and outputs it in a mobile-friendly manner. It also wraps the image in a anchor tag linking to the home page of your WordPress website. However, there are situations where depending on the WordPress theme, you may not necessarily want to have an anchor tag linking to the home page URL of your WordPress website.

To keep things simple, you can continue using the_custom_logo(); as you always would have. This keeps it consistent across all of the WordPress themes you will develop over time, making it easier to maintain.

The simple solution to me was to just filter the HTML output of the function the_custom_logo(); on an “as needed” basis. This can easily be done via wp_kses();.

Here’s how you can filter the HTML output of the_custom_logo();, in order to strip the unwanted anchor tag which wraps the image tag.

As usual, if you came across this article and found it useful, please write a quick comment. Doesn’t take long and you don’t need to register. Simple “thanks” is good enough in my opinion.

If you know of a better or easier way, or could improve this snippet, please share your thoughts in the comments as well. Thanks for reading.

 

Leave a Reply