admin管理员组文章数量:1414621
I have a custom theme with a bunch of custom post types. I want to keep my "news" post type to display as a paginated list (that links directly to the external news article - already figured this part out), but I want to get rid of all single pages that get created when I add a news news post. Basically the opposite of this: How do I create new content pages for my Custom Post Type?. I apologize if this as too vague, not a developer. Just let me know what additional info is needed to determine a solution.
Thanks in advance.
I have a custom theme with a bunch of custom post types. I want to keep my "news" post type to display as a paginated list (that links directly to the external news article - already figured this part out), but I want to get rid of all single pages that get created when I add a news news post. Basically the opposite of this: How do I create new content pages for my Custom Post Type?. I apologize if this as too vague, not a developer. Just let me know what additional info is needed to determine a solution.
Thanks in advance.
Share Improve this question asked Sep 3, 2019 at 18:59 Mike KCMike KC 131 silver badge4 bronze badges1 Answer
Reset to default 1Because you are linking to external news articles you would like to prevent users from getting to the /news-article/article-title/
url that is created for a new post and would have no real content?
You could do something like this: How to disable the single view for a custom post type?
The code below is from that answer. Add it to your functions.php, making sure to change news_article
to the actual post type slug. This should 301 redirect a user trying to hit that single post. You may want to test this first using 302 as many browsers will cache a 301 and can be difficult to clear out.
It defaults to 302, so remove the , 301
to set it to default if you'd like to try with a 302.
add_action( 'template_redirect', 'news_article_redirect' );
function news_article_redirect() {
$queried_post_type = get_query_var('news_article');
if ( is_single() && 'news_article' == $queried_post_type ) {
wp_redirect( home_url(), 301 );
exit;
}
}
本文标签: Remove single page for custom post type
版权声明:本文标题:Remove single page for custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745188827a2646811.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论