Forums

Join
bbPress Support ForumsPluginsreplacing page title

Info

replacing page title

  1. 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

  2. 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');
  3. 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');
  4. +1 johnbillion

  5. 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"?

  6. By the way I came out here, I isolated the title function as suggested and the title is rewritten. Thanks!

  7. 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.

  8. Hey Sam,

    thanks for the explanations.

    I got the whole stuff working and my "seo plugin" is almost released.

  9. You must log in to post.