S
S
Suffering19922017-10-10 11:57:57
Internationalization and localization
Suffering1992, 2017-10-10 11:57:57

Virtual Multisite on Wordpress, how to implement?

The idea is simple: there is a single site on wordpress "example.ru"
It is necessary:
​​1. Make it possible to add subdomains "moskva.example.ru", "spb.example.ru", "krasnodar.example.ru", etc.
2. Make it one and the same site, only change for each city: title, description and other places where the name of the city is used.
3. Need a sitemap for each subsite.
Do not:
1. Create a network.
2. Use multiple sites.
An example of how it works https://korkino.mebel-store.com/
Thanks to everyone in advance for possible ideas.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2017-10-10
@Suffering1992

In general terms:
1. Configure the server to treat example.ru and *.example.ru as the same WP site
2. In wp-config.php, set the site URLs using constants (they take precedence over the values ​​from the database) , and set the values ​​of these constants dynamically on the go, depending on the requested address:

define( 'WP_HOME', $_SERVER['SERVER_NAME'] );
define( 'WP_SITEURL', $_SERVER['SERVER_NAME'] );

3. In the same config, add one more constant for convenience, say, SUBDOMAIN. We take $_SERVER['SERVER_NAME'], get the subdomain name from it and put it in this constant.
4. Further, in the right places, take the value of this constant and act according to the circumstances. For example, hook into the the_title filter and modify the title based on the value of the constant.
5. The sitemap might take a little longer. But there shouldn't be any particular problems.
6. Perhaps, in the process of debugging, some other minor nuances will come out, but hardly anything serious.
UPDATE:
I was thinking about the idea, but something else came to mind - we need to reduce code repetition in those places where the data will be modified depending on the value of the SUBDOMAIN constant. I would set up some array in which the values ​​of subdomains will act as keys, and the necessary data will be the values ​​of the array. Where to store it, in the database or in the config - it does not matter. Something like:
$data = [
    'moskva' => [
        'name' => 'Москва',
        'term_id' => 11, // ID термина таксономии cities, которая может использоваться для группировки контента, это позволит на "подсайтах" показывать только релевантный контент
        'title_suffix' => ' в Москве и области', // динамическая часть тайтла сайта / страниц
        ...
    ],
    'spb' => [
        ...
    ],
    ...
];

Well, to access this data:
$title = $title . $data[ SUBDOMAIN ]['title_suffix'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question