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 your site's search functionality by forcing WordPress to only look at post titles while ignoring body content. By utilizing the posts_search filter and the $wpdb object, you can modify the SQL WHERE clause to specifically target the post_title column. This is highly effective for documentation sites or blogs where title matches are more relevant than deep content matches, providing users with a faster and more precise search experience.
If you want your WordPress search to check only post titles and ignore content, here's a quick method using the posts_search filter in your theme:
functions.php file.
function limit_search_to_post_titles($search, $wp_query) {
if (is_search() && !is_admin()) {
$search_terms = $wp_query->query_vars['s'];
if (!empty($search_terms)) {
global $wpdb;
$search = $wpdb->prepare(" AND {$wpdb->posts}.post_title LIKE %s", '%' . $wpdb->esc_like($search_terms) . '%');
}
}
return $search;
}
add_filter('posts_search', 'limit_search_to_post_titles', 10, 2);
That’s it! Now your search will filter by post titles only, excluding body content and pages.
Search our archives or reach out to our team for solutions and expert advice.
150+ मुफ्त डेवलपर और SEO टूल्स
JSON, CSS/JS Minifier, SEO Analyzer & more — DotIAM Tools par
JSON, CSS/JS मिनिफायर, SEO एनालाइज़र और भी बहुत कुछ — DotIAM Tools पर
Our other free platforms you'll love
1000+ Hindu, Muslim & Modern baby names with meaning in Hindi & English
20+ AI-powered tools, 200+ Expert plant care guides and many more
150+ free online tools — AI, Astrology, Calculator, Kids Learning aur bahut kuch
Daily aarti, chalisa aur sandhya prayers — free devotional content