0

so I wanted to change the <title> head element and found this post: Change the_title() of a page dynamically

I followed and my function now looks like this:

# set title per page
function vendor_module_filter_the_title($title)
{
    # exclude menus
    if (!in_the_loop()) {return $title;}

    # collection page
    if (is_page_template('page-collection.php')) {
        if (strpos($_SERVER['REQUEST_URI'], 'category1') !== false) {
            $title = 'title 1';
        } else if (strpos($_SERVER['REQUEST_URI'], 'category2') !== false) {
            $title = 'title 2';
        }
    }

    return $title;
}

add_filter('the_title', 'vendor_module_filter_the_title', 10, 2);

however after CTRL + F5 it doesn't seem to work, I've tested with other meta tags using add_action('wp_head', ...) but it doesn't seem to work for title using add_filter - how do I go about debugging? How do I find out why this function doesn't work?

where am I going wrong? :/

1 Answer 1

0

the answer (taken from: https://stackoverflow.com/questions/36087390/add-filterwp-title-doesnt-replace-my-title-tag-wordpress-plugin) was to do this:

add_filter( 'pre_get_document_title', 'vendor_module_filter_the_title', 999, 1 );

this is due to the YOAST SEO plugin and the above is the found workaround.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.