Reputation: 1271
I'm trying to change the title in WordPress:
function change_title_func($title) {
if( in_the_loop() && !is_archive() ) { // Avoiding Menu Items
return $title.'<span class="cls"></span>';
}
}
add_filter('the_title', change_title_func(), 10, 2);
but the anchor's title attribute also gets changed and I don't want that. Example:
<a href="..." title="title<span class=" cls"="">">title<span class="cls"></span></a>
This hapens most likely because the same filter is used in both places. How can I skip this title attribute change since they use the same filter?
Note: I'm trying to do this inside a plugin I'm working on, so editing the child theme won't be an option.
Upvotes: 0
Views: 468
Reputation: 1429
You can't, that filter is used by the function [get_the_title][1], the filter only send 2 parameter the title
and the post_id
and this function is very used.
The best way to go is create a new function call it get_the_title_with_span
and add your extra markup there, the change the get_the_title
function for get_the_title_with_span
where you want to add the extra markup.
Upvotes: 1