Answer the question
In order to leave comments, you need to log in
How to make city subdomains and meta tags through shortcodes for each city in wordpress?
Hello everyone,
there is a site for WordPress services, you need to create city subdomains, and for them meta tags (title and description) that will differ only by city.
Here is an example of a meta tag: I provide a "shortcode" service, where the shortcode is, for example, "in Moscow" and each subdomain will have its own city shortcode.
I know that there is a plugin in Bitrix that allows you to display cities in meta tags and site content on subdomains through shortcodes. Those. I assign the city to the subdomain links of the gorod.site.ru type in the plugin, and for the city the shortcode in the required case, then I add the shortcode to the meta tag and it changes the city subdomain depending on the subdomain.
The content on subdomains should match 100% with the content on the main site, only the title, description, Yandex Map for a specific city with the office tag should differ, and cities should be added to h1 titles. How can this be implemented?
Answer the question
In order to leave comments, you need to log in
You can influence the formation of meta tags through functions.
Auto Generate Meta Description Meta Description from The_content
Pasting this code snippet into your WordPress theme's functions.php file will automatically generate a meta description from your post, stripping out shortcodes and tags. Also make sure you have this code in your header.php file otherwise this snippet won't work.
function create_meta_desc() {
global $post;
if (!is_single()) { return; }
$meta = strip_tags($post->post_content);
$meta = strip_shortcodes($post->post_content);
$meta = str_replace(array("n", "r", "t"), ' ', $meta);
$meta = substr($meta, 0, 125);
echo "<meta name='description' content='$meta' />";
}
add_action('wp_head', 'create_meta_desc');
echo "<meta name='description' content='$meta' />";
wrap it in textecho "<meta name='description' content=' \"текст до города\" . $meta . ' /> " . \"текст после города\";
Create a subdomain and set up yaost, the principle is similar to Bitrix with shortcodes
Do you want to make a city template, then spread this template across subdomains, and depending on the subdomain, it will change the value of the short code?
You need to do 2 things:
1) Compose city shortcodes in different cases
for meta tags, it is better to use do_action instead of shortcodes
2) Check your subdomain, and if it is such and such, then display such and such a city.
<?php echo $_SERVER['SERVER_NAME']; ?>
What is the question?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question