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

I'm trying to add some string replacements to the_title() -

function format_title($content) {
    $content = str_replace('&','&<br>', $content);
    $content = str_replace('!','!<br>', $content);
    return $content;

When I try and replace ampersands I get an additional "#038;" after the replacement (ASCII for ampersand), I'm not sure as to why this occurs (security reason?) or how to create a workaround. I've tried replacing "&" with "& amp ;" but with no effect.

The goal is to add line breaks at certain points of a title to create a better flow in the typography. Both the database and the site has UTF8 encoding.

share|improve this question
up vote 2 down vote accepted

&#38; is essentially synonym of &amp;. In the_title filter wptexturize() runs with priority 1 (important!) and makes this replacement.

So by the time it gets to your format_title() at priority 11 - instead of replacing lone & symbol you replace (and break) chunk of &#38; character entity.

So you can:

  1. move your function to priority 0 and it will run before texturize
  2. leave priority at 11 but replace $#38; instead of just &
share|improve this answer
That did the trick! Thanks! – Staffan Estberg Oct 30 '11 at 20:49

Here is one more solution:-

wp-includes\formatting.php >> esc_url ()  >>  comment the line <br> $url = str_replace( '&amp;', '&#038;', $url ); 

It works for me.

share|improve this answer
Never edit the core, even if it works! Your changes may not stay upon next update! – Pothi Oct 8 '13 at 11:03

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.