This code modifies various URLs in WordPress generated by the Yoast SEO plugin to replace the domain with the current domain.
Here's a breakdown of what the code does:
-
The code adds filters to various Yoast SEO functions in the
functions.php
file to modify specific URLs. These filters ensure that the URLs are updated with the current domain. -
The
change_domain_in_link
function is a callback function used by the filters. It takes a URL as input and replaces the domain in the URL with the current domain. It uses thestr_ireplace
function to perform the replacement. -
The
recursive_array_search_callback
function is a helper function used by thechange_domain_in_links
function. It recursively searches for a specific value in a multidimensional array and applies a callback function to the found value. In this case, it is used to search for URLs starting with "https://" in the schema graph data. -
The
change_domain_in_links
function modifies the URLs in the schema graph data generated by Yoast SEO. It uses therecursive_array_search_callback
function to search for URLs starting with "https://" and replaces the domain in those URLs with the current domain.
Overall, this code ensures that URLs generated by Yoast SEO, such as canonical URLs, Open Graph URLs, and schema graph URLs, are updated with the current domain. This can be useful when migrating a WordPress site to a new domain or when working with different environments.