Ecommerce Shopify WordPress Discussion

WordPress – use a different domain for a certain post type

I'm trying to work out if it's possible to have a WordPress custom post type using a different domain. For example, let's say my main site is, and I have a custom post type called "Books" - is it possible to have that post type on rather than I've looked into domain mapping and redirects but I'm struggling to find a straight answer on if/how it's possible. I'd also need this to be done automatically rather than having to add redirects to the .htaccess file manually, or having to restart the server, for example. Any ideas?
this isn't hard, point all the domain to your wordpress install, then just use superglobal $_SERVER and global $post to perform conditional to redirect or not base on $post->post_type. example; injecting the redirect login on wp action add_action('wp', function() { global $post; //map your domain to post type $post_type_domain_map = [ 'books' => '', // not needed, just example mapping all post type to specific domain // 'post' => '', // 'page' => '' ]; //grab the domain name from the request; you can also use parse_url $host = $_SERVER['HTTP_HOST']; //check if it should redirect base on following condition $shoud_redirect = ( $post // if has valid post && isset( $post_type_domain_map[$post->post_type] ) // if post type is map to a domain && $host != $post_type_domain_map[$post->post_type] // if the request host is not the correct domain for the current post_type ); // stop the execution if it should NOT redirect if ( !$shoud_redirect ) return; // get the post permalink but replace the host depending on the post type // e.i. will transform to and vice-versa $domain_specific_permalink = str_replace(home_url(), $_SERVER['REQUEST_SCHEME'].'://'. $post_type_domain_map[$post->post_type], get_permalink($post)); // check if headers have been set otherwise perform redirect if (!headers_sent()) { wp_redirect($domain_specific_permalink, 301); exit; } });

February 4, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.