admin管理员组文章数量:1328380
I have a domain domain
and subdomain materials.domain
At the domain
scope, I created a custom post type called resources
and a portfolio grid (using Elementor) to display it's featured image with the title.
When clicking on the grid item, the single post is shown for example: domain/resources/resource-title
I'd like to remove the single post from the domain and redirect on click to materials.domain/resource-title
. I already have this page on the materials
subdomain).
How can I achieve that?
I have a domain domain
and subdomain materials.domain
At the domain
scope, I created a custom post type called resources
and a portfolio grid (using Elementor) to display it's featured image with the title.
When clicking on the grid item, the single post is shown for example: domain/resources/resource-title
I'd like to remove the single post from the domain and redirect on click to materials.domain/resource-title
. I already have this page on the materials
subdomain).
How can I achieve that?
Share Improve this question edited Jul 16, 2020 at 14:15 Fahad 235 bronze badges asked Jul 6, 2020 at 14:34 user1301037user1301037 836 bronze badges 7 | Show 2 more comments2 Answers
Reset to default 5 +50Sometimes this would be achievable with add_rewrite_url
but it looks like in this case it's not as you need to redirect to a different domain.
In this case you need .htaccess or nginx rules to do this, so you need to add something like this to your nginx config for domain only, in order to rewrite those URLs:
rewrite ^/resources/(.+) https://materials.domain/$1 permanent;
You'll likely need to restart nginx after you add this to the config file.
Happy to help if this doesn't do exactly what you want. There's more examples of nginx rewrite rules here: https://www.thegeekstuff/2017/08/nginx-rewrite-examples/
If you want to do it from WordPress environment itself..
function wpse370481_redirect_url() {
if ( is_singular( 'resources' ) ) {
global $post;
$path = $post->post_name;
$redirect_url = 'https://materials.domain/' . $path;
wp_redirect( $redirect_url );
exit;
}
}
add_action( 'template_redirect', 'wpse370481_redirect_url' );
Havn't tested this code as I currently don't have a setup to test this, but in theory, the code should work.
本文标签: multisiteRedirect Single Post CPT (Custom Post Type) to a specific URL
版权声明:本文标题:multisite - Redirect Single Post CPT (Custom Post Type) to a specific URL 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742258043a2441990.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
domain/resources/resource-title
redirects you immediately tomaterials.domain/resource-title
? – mozboz Commented Jul 6, 2020 at 15:44