Reputation: 3674
I would like to change the title of my blog posts. I can't do that in the theme. It needs to be done with a filter.
I have added the following code to the functions.php in the theme that is used on my Wordpress blog:
function overwrite_post_title($title, $sep) {
//global $post;
//if ( is_single($post->ID) && !is_attachment($post->ID) )
//if ( is_single() && !is_attachment() )
var_dump($title);
$title = "Test";
return $title;
}
add_filter('wp_title', 'overwrite_post_title', 10, 2);
It is supposed to change the title of a post. But it does nothing. It is not even being executed.
Upvotes: 1
Views: 212
Reputation: 903
Try this code or increase your priority
to large value
function overwrite_post_title($title="", $sep="") {
$title = "Test";
return $title;
}
add_filter('wp_title', 'overwrite_post_title', 10, 2);
You increse priority
by
add_filter('wp_title', 'overwrite_post_title', 1, 2);
Upvotes: 0
Reputation: 1590
Try to use this
add_filter( 'the_title', 'ta_modified_post_title');
function ta_modified_post_title ($title) {
if ( in_the_loop() && !is_page() ) {
$title = "Test (modified title)"; // your title name
}
return $title;
}
Upvotes: 1