Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress WordPress Hooks - Actions and Filters Filter Functions in WordPress The apply_filters Function

Hi how to change the blog title with add_filter? details below

i want to add a prefix to all the blog title by modifying the all ready applied filter .

when i searched i got this: apply_filters( 'single_post_title', string $_post_title, object $_post )

what action do i have to modify this ?

add_filter('single_post_title', 'my_title');

function my_title(???){ ??? }

1 Answer

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

For the function apply_filters:

  1. the first parameter 'single_post_title' is correct, that is what you want to change.
  2. the second parameter should be the title you want to pass the title. If you want to call a function, you would not use quotes and you would need to return the title.
  3. the actual post object, so most likely $_post
add_filter('single_post_title', title_function, $_post);

function title_function() { 
    return 'my title';
}