I want to use Myanmar Unicode text on my blog. Unfortunatly, pseudo-Unicode Myanmar fonts are common. So, I am writing a plugin that will suround all Myanmar phrases with HTML span tags, and use css to select the proper font.
Everything works fine for content, comments, etc. However, after adding HTML using the the_title hook, that HTML gets escaped, and then included in the title attribute of the link tag in the recent posts section. In addition, I’m seeing the raw HTML tags in the post name on my admin post screen.
How should I go about solving this problem? I prefer to do everything from within my plugin, not change the theme files or something.
Here is my code:
add_filter( 'the_title', 'addThemSpans');
function addThemSpans($theTitle) {
// 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;
}
As it is now, the title attribute for the link in the recent posts sidebar widget is set to:
LatinTextHere <span class='myText'>ကကကကက</span><span class="myText">ကကကကက</span> MoreLatinText
Which is not right.
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.
-
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.
-
You could also write your own recent posts widget.
-
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.