Are you really going to buy and register different domain names for every location? Some may already be taken. Why not use subdomains, they’re usually free up to a point? For example spokane.example.com or seattle.example.com. Simpler would be to use the same domain and alter the URL: example.com/pagename/spokane/. The simplest would be to pass the location as a query string: example.com/?city=spokane.
Whichever approach you use, PHP can extract such data from the URL, either from $_SERVER or $_REQUEST and use it in generating page output. This can be done via template code, shortcode, or custom block, depending on where you want the passed name to occur in content.
I’m not aware of such a plugin, but that doesn’t mean one does not exist. I tried searching https://ww.wp.xz.cn/plugins/search/dynamic+content/ but only a few of the many results sounded promising.
-
This reply was modified 3 years, 10 months ago by
bcworkz. Reason: corrected var names
Thread Starter
kflow0
(@kflow0)
How would the code go for that? @bcworkz
Going with the simplest solution (URL query string), roughly something like:
// replaces "%%cityname%%" in any post content with passed 'city' value from URL
add_filter('the_content', 'kfl_merge_city_name');
function kfl_merge_city_name( $content ) {
if ( array_key_exists( 'city', $_REQUEST )) {
$city = $_REQUEST['city'];
// must add code to validate, sanitize, and escape $city here
$content = str_replace('%%cityname%%', $city, $content );
}
return $content;
}
Incomplete and untested, but that’s the gist of it.