0
votes

I am trying to change the default blog post title (Hello world) in WordPress

add_filter('the_title', 'modify_all_titles', 10, 2);

function modify_all_titles($title, $id) {

return 'My default page title';
}

As you can see it changes ALL blog posts titles.

How can I change only the default page title (The first post, or post ID1 for example)?

Thank you in advance.

1

1 Answers

0
votes

you should use wordpress conditional tags

in your case is_single() is the appropriate function.

to check if the current query is a post with id 1: is_single(1)

same thing with post's slug: is_single('hello-world')

your code with conditional tags:

add_filter('the_title', 'modify_all_titles', 10, 2);

function modify_all_titles($title, $id) {

return $id == 1 ? 'My default page title' : $title;
}

you can also compare $id with hello world's id