Info
- 8 posts
- 3 voices
- Started 3 years ago by Olaf
- Latest reply from Olaf
- This topic is resolved
replacing page title
-
- Posted 3 years ago #
Hi,
I'm busy with some plugin that will do some SEO tasks for bbpress.
On thing seem to be harder than I thought. I would like to write new page titles in some circumstances. The next "filter" code doesn't work:
remove_filter('bb_get_header', 'bb_get_title'); apply_filters('bb_get_title', 'PHP Scripts Development Forum');which function is called before I need to use the remove filter funtion? (the guy from the WP SEO plugin is using some str_replace function, very strange)
Thanks
-
- Posted 3 years ago #
The second parameter in apply_filters() needs to be a function that returns the text to be displayed in the title. Eg:
function my_title( $title ) { return 'PHP Scripts Development Forum'; } apply_filters('bb_get_title', 'my_title'); -
- Posted 3 years ago #
Oh hang on, that's not right either. Use add_filter(). Try this:
function my_title( $title ) { return 'PHP Scripts Development Forum'; } add_filter('bb_get_title', 'my_title'); -
- Posted 3 years ago #
+1 johnbillion
-
- Posted 3 years ago #
Hi Thanks for helping.
it doesn't work :(
this is the function I use (stripped the other code)
function my_title($title) { return 'PHP Scripts Development Forum'; } function create_meta() { if (is_front()) { remove_filter('bb_title', 'bb_get_title'); add_filter('bb_get_title', 'my_title'); // code to create the meta data } else { // do something else } } add_action('bb_head','create_meta');maybe it doesn't work because I add the filter within that "action"?
-
- Posted 3 years ago #
By the way I came out here, I isolated the title function as suggested and the title is rewritten. Thanks!
-
- Posted 3 years ago #
The problem with your code was that you were adding a filter to bb_title via an action run when the title was already written to the browser. You should have added the filter at bb_init or just left it on it's own in the plugin.
Also, I don't think there is particularly a need to remove the existing filter on bb_title in your case.
-
- Posted 3 years ago #
Hey Sam,
thanks for the explanations.
I got the whole stuff working and my "seo plugin" is almost released.
-
You must log in to post.