Is there a way to insert images into a post title? It would also need to display the alt text in the <title> tag, permalinks, etc.

The reason I need to do this is I have a client who want their logo used in page titles instead of plain text. Therefore, the image could be anywhere in the title, so I can't just append/prepend the image.

The only solution I can think of would be to do a find and replace using javascript, but this doesn't seem like a great solution...

  • 1
    To clarify, they want to use their logo in place of their business name within titles? If this is the case I would look at using a filter - codex.wordpress.org/Plugin_API/Filter_Reference/the_title the function can then replace the specific text with the image tag/information.
    – nvwd
    Jul 30, 2012 at 15:15

1 Answer 1


A search and replace solution does sound viable. I wouldn’t do it via JavaScript, though.

add_filter('the_title', 'wpse60174_logo_in_title', 10, 2);

function wpse60174_logo_in_title($title, $post_id)
    // Add a <span> around the company name
    return preg_replace('~\bCompany\s+Name\b~i', '<span class="company">$0</span>', $title);

With the extra span in place it is just a matter of applying some custom styles to it. You can provide different styles depending on where the title is shown. You may even decide to not replace the company name with a logo image in some place. It’s a flexible setup with clean HTML.

/* A demo CSS rule */
h1 > .company { display:inline-block; background:url(logo.png); width:100px; height:20px; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.