InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress customization tutorials

  • Handle pagination in wordpress custom php code
  • How to and why disable wordpress cron
  • How to customize wordpress image alt tag
  • How to display date in wordpress pages
  • How to display wordpress page list with specific custom field value
  • How to display wordpress top level pages
  • How to hide a post from home and RSS feed in wordpress
  • How to include bootstrap javascript and css in wordpress post
  • How to include wordpress pages in archives
  • How to override priority and change frequency in Yoast xml sitemap
  • How to remove xmlrpc from wordpress headers
  • How to setup wordpress custom query params with pretty url format
  • How to show wordpress pages on front page with skip_home custom field
  • How to use google custom search for wordpress site
  • How to write custom php in wordpress
  • No frills social share links for Wordpress sites
  • Using Wordpress custom field for displaying code
  • Wordpress - add content filter after shortcode execution
  • Wordpress - customize category and tag links
  • Wordpress - customize facebook plugin opengraph meta tags
  • Wordpress - customize posts per page for tag, category and date archive pages
  • Wordpress - exclude specific posts from archive pages
  • Wordpress - get posts/pages with missing meta key
  • Wordpress - how to add filter to description meta tag
  • Wordpress - how to create custom tag cloud
  • Wordpress - how to exclude specific tag posts from a tag archive page
  • Wordpress - write custom php log to separate file
  • Wordpress how to check if a post is being viewed by admin
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress customization

How to hide a post from home and RSS feed in wordpress

By admin | Last updated on Mar 18, 2016

Sometime we want to hide a post from wordpress home page. One not-so-good alternative is to create it as a page. One drawback of that approach is that it does not have tags, categories and will not come in tag/category browse pages. This article will cover how this can be achieved if there is any performance impact.

How posts are displayed in wordpress

By default when we hit home page and navigate, wordpress queries wp_posts table and its a simple query since all post are included. Here is how a query (not verbatim) looks like:

SELECT wp_posts.ID FROM wp_posts  WHERE wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')  ORDER BY wp_posts.post_date DESC LIMIT 0, 10

To be able to prevent some posts from appearing on home page (or RSS feed, etc.) this query needs to be modified.

Using WP hide post plugin

WP hide post plugin is a good plugin which let you achieve these functionalities. Here is how the wordpress post edit admin UI looks like when plugin is instaled and activated.
wp-hide-post-ui

Here is what plugin doc says:

WP hide post enables a user to control the visibility of items on the blog by making posts and pages selectively hidden in different views throughout the blog, such as on the front page, category pages, search results, etc…

The plugin was last updated on 2010-1-3. So I was initially little worried about using it. But it is pretty simple and worked nicely. Moreover its a good idea to understand how plugin is doing it so that one can fix things if needed.

How WP hide post plugin works

The plugin adds a filter to posts_join_pages which adds a join clause in query to get posts from wp_posts table (on wp_post_options).

add_filter('posts_join_paged', 'wphp_query_posts_join');

Here is how the query for showing posts on home page looks like if you use the plugin:

SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_postmeta wphptbl
ON wp_posts.ID = wphptbl.post_id
and wphptbl.meta_key like '_wplp_%'
AND ((wp_posts.post_type = 'post' AND wphptbl.meta_key = '_wplp_post_front' ) OR (wp_posts.post_type = 'page' AND wphptbl.meta_key <> '_wplp_page_flags' AND wphptbl.meta_key not like '_wplp_%' ))

Note that this will add little overhead to query in terms of performance. Also post will still apear in sitemap and other browse pages.

Performance and other approaches

Since the query to get posts is on two tables, there will be some (very little if number of posts are not too many) performance impact. If your blog posts are under 10000 or so and you are using some caching plugin like W3 total cache, then the impact can be pretty much neglected for all practical purpose.

In case you are obsessed about performance, then you may want to explore adding a filter to posts_where_pages and excluding the post ids which are in php code itself. You may have to auto generate that part of php code using some automated script and your own workflow.

function some_function_to_exclude_posts_in_where($where) {
  // code to append ID not in (id1, id2, id3) to $where
}
add_filter('posts_where_paged', 'some_function_to_exclude_posts_in_where');

This approach may be harder to maintain and not recommended. But I think its good to be aware of all feasible options.

Suggested posts:

  1. How to add tag and category to wordpress pages
  2. jQuery – difference between html() and text()
  3. Fetch wordpress rss feed as FeedBurner user agent on command line
  4. HTML li tag
  5. PHP check if key exists in array
  6. Command line – run python webserver
  7. How to show wordpress pages on front page with skip_home custom field
  8. How to ping feedburner to force update rss cache
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Tutorials, Wordpress, Wordpress customization
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress