WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...

share|improve this question
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 '12 at 15:15
up vote 3 down vote accepted

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; }
share|improve this answer
Perfect, thank you! – slm_92 Jul 30 '12 at 15:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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