admin管理员组文章数量:1310221
By default WordPress pushes out a whole array of pages I don’t want or need - archive, author, blog, monthly, recent posts, categories, comments, attachment, taxenomies, search, search results, and probably a few others I’ve missed.
Most of the time I’m building regular broshure websites with no need for anything except a few fairly static pages. How do I get rid of all the other pages? Is there a plugin that will do this? Do I have to set up a dozen redirects in the .htaccess? I’ve tried searching, but all I find is how to hide parts of a page, or customise the sitemap to hide from searches. But I don't want those pages at all, so even entering the direct URL shouldn't work.
By default WordPress pushes out a whole array of pages I don’t want or need - archive, author, blog, monthly, recent posts, categories, comments, attachment, taxenomies, search, search results, and probably a few others I’ve missed.
Most of the time I’m building regular broshure websites with no need for anything except a few fairly static pages. How do I get rid of all the other pages? Is there a plugin that will do this? Do I have to set up a dozen redirects in the .htaccess? I’ve tried searching, but all I find is how to hide parts of a page, or customise the sitemap to hide from searches. But I don't want those pages at all, so even entering the direct URL shouldn't work.
Share Improve this question asked Apr 15, 2013 at 17:02 EysteinEystein 2351 gold badge2 silver badges10 bronze badges5 Answers
Reset to default 7You could redirect anything that's not a page or admin to home via the parse_query
action:
function wpa_parse_query( $query ){
if( ! is_admin() && ! $query->is_page() ) {
wp_redirect( home_url() );
exit;
}
}
add_action( 'parse_query', 'wpa_parse_query' );
If it's not an admin screen or a query for a page, it'll redirect. You can see all of the types of pages this will remove under the Conditional Tags page in Codex.
Joost de Valk's WordPress SEO plugin is capable of disabling most, if not all, archives you mention:
You can user another small script, without adding any plugin. There is a post here and the code to add in the index.php of your theme is this:
if(is_archive()) {
// force 404
$wp_query->set_404();
status_header( 404 );
nocache_headers();
include("404.php");
die;
}
Hope you find it useful.
For anyone wondering, I ended up using .htaccess 301 redirects.
# Redirect useless pages
Options +FollowSymlinks
RewriteEngine on
RedirectMatch 301 ^/portfolio/.*$ /gallery/
RedirectMatch 301 ^/author/.*$ /
RedirectMatch 301 ^/category/.*$ /
RedirectMatch 301 ^/tag/.*$ /
RedirectMatch 301 ^/20.*$ /
The blogpost archive ^/20.*$
isn't ideal, but it will have to do for now. Also don't know what other pages I might've missed.
It can also be achieved using the template_redirect hook.
You can check for each type of archives pages, or "disable" them altogether.
- Return a 404error or redirect to another page, I prefer the 404 approach-
In functions.php
:
/* Disable archives pages */
add_action('template_redirect', 'my_disable_archives_function');
function my_disable_archives_function()
{
/* Conditional checks examples:
is_category()
is_tag()
is_date()
is_author()
is_tax()
is_search() ... */
// Return a 404 for all archive types, except the my_custom_post_type archive.
$post_types = array('my_custom_post_type');
if ( (is_archive() && !is_post_type_archive( $post_types )) )
{
global $wp_query;
$wp_query->set_404();
status_header(404);
}
}
本文标签: privateHow do I remove unwanted pages like archivesearchetc
版权声明:本文标题:private - How do I remove unwanted pages like archive, search, etc.? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741845114a2400736.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论