What is the proper filter to add html to a post / page title?

the_title is the correct hook. You can confirm that by checking the source.

What you are doing is a bit odd, but it makes sense. Clever solution but I don’t think it was expected. The problem you having seems to be with this line:

http://core.trac.wordpress.org/browser/tags/3.5/wp-includes/default-widgets.php#L574

<a href="<?php the_permalink() ?>" title="<?php echo esc_attr( get_the_title() ? get_the_title() : get_the_ID() ); ?>"><?php if> (get_the_title() ) the_title(); else the_ID(); ?></a>

And there is no hook that will help you. The widget grabs the title with get_the_title and doesn’t pass it through anything that you can manipulate.

I think you may need to rethink your approach.

  1. If this is a situation where you can edit the theme you can remove your filter before the sidebars runs and add it back afterwards. I think that is the most straightforward way to do it but may not be possible in you case.

  2. You could also write your own recent posts widget.

  3. You could manipulate your fonts with Javascript– not sure it that would be robust enough for you.

You might be able to check for an $instance variable in your filte and sort out whether you are dealing with a widget or not.

add_filter( 'the_title', 'addThemSpans');
function addThemSpans($theTitle) {
  global $instance;
  var_dump($instance); // see if this works.
  // functionality to add span tags to $theTitle so that a title that looks like this...
    // LatinTextHere ကကကကက​ MoreLatinText
  // becomes this...
    // LatinTextHere <span class="myText">ကကကကက</span> MoreLatinText
    // in the final output.
  return $theModifiedTitle;
}

I don’t know if that will work or not, but if so it will give you something to switch on and you won’t have to edit the theme. Edit: Tested. Sadly, doesn’t work.

Leave a Comment