Reputation: 155
Is there some kind of code I can use to edit the post title before it renders?
It's to do with translation.
For example, I have a post title such as "ITALIAN - RED" and I'd like to change it to "ITALIANO - ROSSO" when it appears on the page. (What I'm after is actually a lot more complicated than this but this is the idea behind it all.)
If it's possible, I'd like to do this on individual posts as well as pages like POSTS-PAGES which lists all recent posts, widgets which list latest posts and search results.
Any help appreciated!
Upvotes: 0
Views: 498
Reputation: 1502
To change the specific post title use the filter hook the_title
.
See the below code :
function change_title( $title ) {
if ( $title == 'ITALIAN - RED' ) {
// Do something with the title
return 'ITALIANO - ROSSO';
}
}
add_filter( 'the_title', 'change_title' );
Upvotes: 1