Someday I will describe the way of creating a multisite for WordPress without database clones and installing plugins. But in this article I am describing a solution when several sites work with the same database and with the same admin panel, and for example, for a subdomain I need to automatically change the content (in this case, the city).
Copy and paste the function into functions.php as shown below:
$host = $_SERVER['HTTP_HOST'];
if($host == "sub.domain.com" or $host == "www.sub.domain.com") {
function replace_content($content) {
$content = str_replace('first phrase to replace', 'edited first phrase',$content);
$content = str_replace('second phrase to replace', 'edited second phrase',$content);
$content = str_replace('third phrase to replace', 'edited third phrase',$content);
return $content;
}
add_filter('the_content','replace_content');
}
Similarly, you can change the content on the fly depending on the language versions, when instead of checking the host, you can check the language prefix in the link.
WEBinP Your guide to resolving CMS optimization, Web Development and SEO problems