Suggested articles based on your search query
- Disable HTML in Comments Entirely on 23/02/2011
Disable some WordPress Pages of Little Use
There are many situations in which you might want to disable certain WordPress pages. For example, you choose to use Google Custom Search (CSE) instead of the default WordPress search, and you want to make sure a request like http://example.com/?s=disable+page will not make regular search result pages visible.
Another obvious example is that if you don’t update your blog often, your daily archive pages will just return 404, or worse, it will contain no more than one post, which makes such archive pages completely useless. So, to avoid unexpected issues, let’s just disable them!
Open your theme’s functions.php and put this in:
- /* Kill attachment, search, author, daily archive pages */
- add_action('template_redirect', 'bwp_template_redirect');
- function bwp_template_redirect()
- {
- global $wp_query, $post;
- if (is_author() || is_attachment() || is_day() || is_search())
- {
- $wp_query->set_404();
- }
- if (is_feed())
- {
- $author = get_query_var('author_name');
- $attachment = get_query_var('attachment');
- $attachment = (empty($attachment)) ? get_query_var('attachment_id') : $attachment;
- $day = get_query_var('day');
- $search = get_query_var('s');
- if (!empty($author) || !empty($attachment) || !empty($day) || !empty($search))
- {
- $wp_query->set_404();
- $wp_query->is_feed = false;
- }
- }
- }
/* Kill attachment, search, author, daily archive pages */
add_action('template_redirect', 'bwp_template_redirect');
function bwp_template_redirect()
{
global $wp_query, $post;
if (is_author() || is_attachment() || is_day() || is_search())
{
$wp_query->set_404();
}
if (is_feed())
{
$author = get_query_var('author_name');
$attachment = get_query_var('attachment');
$attachment = (empty($attachment)) ? get_query_var('attachment_id') : $attachment;
$day = get_query_var('day');
$search = get_query_var('s');
if (!empty($author) || !empty($attachment) || !empty($day) || !empty($search))
{
$wp_query->set_404();
$wp_query->is_feed = false;
}
}
}The snippet above will effectively disable attachment pages, search page, author pages and daily archive pages. Automatically generated feeds for those pages will also be disabled.
Please note the use of $wp_query->set_404();, which allows you to make virtually any page become ‘Page not found’. If making the disabled pages ‘not found’ is not your desired behaviour, you might want to redirect requests for those pages to your homepage, like so:
- // Change $wp_query->set_404(); to
- wp_redirect(get_option('home'));
- exit; // always exit a redirection
// Change $wp_query->set_404(); to
wp_redirect(get_option('home'));
exit; // always exit a redirectionIf you would like to keep author archive pages or attachment pages, just remove the corresponding condition tags (i.e. is_author(), is_attachment()) as well as those variables with the same names (i.e. $author, i.e. $attachment), like so:
- /* Kill search, daily archive pages */
- add_action('template_redirect', 'bwp_template_redirect');
- function bwp_template_redirect()
- {
- global $wp_query, $post;
- if (is_day() || is_search())
- {
- $wp_query->set_404();
- }
- if (is_feed())
- {
- $day = get_query_var('day');
- $search = get_query_var('s');
- if (!empty($day) || !empty($search))
- {
- $wp_query->set_404();
- $wp_query->is_feed = false;
- }
- }
- }
/* Kill search, daily archive pages */
add_action('template_redirect', 'bwp_template_redirect');
function bwp_template_redirect()
{
global $wp_query, $post;
if (is_day() || is_search())
{
$wp_query->set_404();
}
if (is_feed())
{
$day = get_query_var('day');
$search = get_query_var('s');
if (!empty($day) || !empty($search))
{
$wp_query->set_404();
$wp_query->is_feed = false;
}
}
}To extend this even more, it is recommended that you take a look at this codex page.








Is there anyway I can remove the author’s profile page all together?
Great, I will use this code in my plugin. Do not worry, I will share a link.
To Sam: You must remove all author’s links & stuff directly in template. Anyway, you may use
add_action( 'template_redirect','somefunction');and something like
if( '/authorlink/' == substr($_SERVER['REQUEST_URI'], -12) ){ ...but it is not “”clean” solution.