Skip to:
Content
Pages
Categories
Search
Top
Bottom

replacing page title


  • Olaf Lederer
    Participant

    @finalwebsites

    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

Viewing 7 replies - 1 through 7 (of 7 total)

  • John Blackbourn
    Participant

    @johnbillion

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


    John Blackbourn
    Participant

    @johnbillion

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


    Sam Bauers
    Participant

    @sambauers

    +1 johnbillion


    Olaf Lederer
    Participant

    @finalwebsites

    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”?


    Olaf Lederer
    Participant

    @finalwebsites

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


    Sam Bauers
    Participant

    @sambauers

    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.


    Olaf Lederer
    Participant

    @finalwebsites

    Hey Sam,

    thanks for the explanations.

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar