Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
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';