Create Custom Menu in WordPress Dashboard
Complete tutorial on create custom menu in wordpress dashboard. Discover practical examples, implementation tips, and expert advice for WordPress and WooCo
Read More โOptimize user experience by limiting WordPress search results to blog posts using the pre_get_posts action hook. Check if the query is a search and not on the admin side using is_search and !is_admin conditions. Set the post_type parameter to post to automatically filter out static pages and custom post types from the result list. This technical optimization ensures visitors find your latest articles and tutorials without the clutter of non-relevant site pages, making it ideal for content-heavy blogs and technical documentation sites.
By default, WordPress search includes posts, pages, and sometimes custom post types. If you'd like to restrict searches to only blog posts, follow these steps. Step 1: Open your active theme’s functions.php file. Step 2: Insert this code:
function custom_search_only_posts($query) {
if ($query->is_search() && !is_admin()) {
$query->set('post_type', 'post');
}
}
add_action('pre_get_posts', 'custom_search_only_posts');
Step 3: Save the file. Now, only posts will be shown in WordPress search results — pages and other types will be excluded automatically. This approach improves search relevance for blog-based websites by limiting the results to what users most likely expect: your blog content. 
Search our archives or reach out to our team for solutions and expert advice.