0

I recently had someone here help me write a custom function for the WordPress site that I'm developing so that it re-writes the page title when a 404 error is encountered. It's been working exactly the way I'd intended -- however -- it stops working when I activate the Yoast plugin. I don't get any PHP errors or anything, but my page title simply doesn't get re-written.

My assumption is that the Yoast plugin likely already hijacks the re-writing of the page titles, and that it is effectively overriding my custom function.

How would I update the custom method below so that it acknowledges the existence of the Yoast plugin, and so that I can leave the plugin active, yet still preserve the functionality of my custom method that re-writes the page titles?

Thanks,

-- Yvan

<?php
function theme_slug_filter_wp_title( $title_parts ) {
    global $parsed_address, $api_results, $wp_query;
    if ( ! $parsed_address ) {
        return $title_parts;
    }
    $title_parts['title'] = ucwords( $parsed_address ) . ' | AAA Real Estate';
    return $title_parts;
}
add_filter( 'document_title_parts', 'theme_slug_filter_wp_title' );

?>

1
  • Any takers? It's been a couple of weeks now. I realize that I don't really have many reputation points that I could offer up to put a bounty on this one, .. but is there anything else I can do to encourage folks to help me out here? Sep 7, 2021 at 16:29

1 Answer 1

0

Well .. for those of you who might be interested, this is how I succeeded at overriding the Yoast plugin conflict with my 404 page titles:

  1. I added a simple custom method to my mu-plugin file that retrieves the property address:

    function get_property_address() { global $parsed_address; return $parsed_address; }

  2. I added this custom method for creating a custom Yoast variable to my functions.php file:

    function register_custom_yoast_variables() { wpseo_register_var_replacement( '%%propertyaddress%%', 'get_property_address', 'advanced', 'some help text' ); }

    add_action('wpseo_register_extra_replacements', 'register_custom_yoast_variables');

  3. I went in to my Yoast Settings (ie: Search Appearance > Special Pages > 404 pages) and added the "%%propertyaddress%%" custom variable to my 404 page title.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.