humanmade / Mercator

WordPress multisite domain mapping for the modern era.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not everything is mapped with Polylang and Revolution Slider plugins

limmess opened this issue · comments

Hello,

I would grateful if you would fix or help me fix my issue:
I have main domain and site: www.laurapeckauskiene.com
It uses Polylang (https://polylang.pro/downloads/polylang/) and Revolution Slider (https://revolution.themepunch.com/) plugins.

So main page is static page in native language and is a slider.
To choose English, user can press EN flag button or use link www.laurapeckauskiene.com/en

Alias domain is laurapphotography.co.uk.
When entered alias address - pages loads, links are mapped except main page:

  1. If I hover over EN button I still see www.laurapeckauskiene.com/en (Expected is laurapphotography.co.uk/en)
  2. If I enter address laurapphotography.co.uk/en, then I'm forwarded to www.laurapeckauskiene.com/en (Expected is laurapphotography.co.uk/en)
  3. If I hover over site Logo(link) it still shows www.laurapeckauskiene.com. (Expected is laurapphotography.co.uk)

@limmess I see, so this isn't really something Mercator handles for you. If you want the site to be available on both domains you would need to first make sure that the constants WP_HOME and WP_SITEURL in your wp-config.php are dynamic eg:

define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] );
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] );
define( 'COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );

Secondly, WP uses the value from your database when constructing links so you'd have to filter the home option eg adding this to functions.php or a plugin:

add_filter( 'option_home', function() {
    return WP_HOME;
} );

Thirdly I would recommend against having the site available on both domains - it's a bad SEO practice in general as it's duplicate content. The intention behind aliases is to use them redirect to the primary domain - again this isn't something Mercator does for you out of the box as implementations can very from project to project.

You may be able to try out https://github.com/humanmade/Mercator-Redirect and use it in legacy mode to achieve the redirects.

thank you @roborourke
I followed your advice but it is not working:

added to wp-config.php:
define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] );
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] );
define( 'COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );

Then got error:
The constant “COOKIE_DOMAIN” is defined (probably in wp-config.php)

So removed third line and here's what I've got in wp-config.php:

define( 'WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'www.laurapeckauskiene.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] );
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] );

Then added to mercator.php:
$GLOBALS['mercator_current_mapping'] = $mapping;
add_filter( 'site_url', __NAMESPACE__ . '\\mangle_url', -10, 4 );
add_filter( 'home_url', __NAMESPACE__ . '\\mangle_url', -10, 4 );
add_filter( 'option_home', function() { return WP_HOME; } );

Still not working.
Then added at the end of functions.php file:
function wp_cache_get_last_changed( $group ) { $last_changed = wp_cache_get( 'last_changed', $group );
if ( ! $last_changed ) { $last_changed = microtime(); wp_cache_set( 'last_changed', $last_changed, $group ); }
return $last_changed; }
add_filter( 'option_home', function() { return WP_HOME; } );

still nothing.
What I do wrong.
Thank you in advance

@limmess I just checked those sites and looks like it's working as you wanted

I've tried 3 computers, mobile phones, chrome, firefox - issue exists.
Maybe I've explained my problem wrong.
Just enter address: http://laurapphotography.co.uk/en and watch how it is changed to http://www.laurapeckauskiene.com/en/

Odd, definitely didn't see it do that yesterday. WordPress itself automatically redirects to the value in the database as the primary domain. As I mentioned before it's not good SEO practice to have the same site on two URLs so I'm not sure why you want it to work that way.

This problem isn't related to Mercator, nor the other two plugins you mention, rather the way core WP works so I'll close this issue out.

There may be other places to filter in WP_HOME constant but I'm not sure right now. It's not something I've ever tried to do.

Maybe something like https://en-gb.wordpress.org/plugins/multiple-domain/ or https://en-gb.wordpress.org/plugins/multiple-domain-mapping-on-single-site/ is what you're looking for?