The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join

Functions


Exclude Specific Categories from WordPress Search Results

Steps Add the PHP code to your theme’s functions.php file or a PHP snippets plugin. Replace 5, 8, 12 with your actual WordPress category IDs. Save and activate the snippet. Search your website to verify the excluded categories no longer appear.


Prevent WordPress Search from Displaying Pages

/** * Exclude pages from WordPress search results */ function custom_exclude_pages_from_search( $query ) { if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { $query->set( ‘post_type’, ‘post’ ); } } add_action( ‘pre_get_posts’, ‘custom_exclude_pages_from_search’ );


Automatically Add a Copyright Notice to RSS Feed Posts

/** * Add copyright text to WordPress RSS feed content */ function custom_add_rss_copyright_notice( $content ) { if ( is_feed() ) { $copyright = ‘<p>Copyright &copy; ‘ . esc_html( gmdate( ‘Y’ ) ) . ‘ Your Website Name. All rights reserved.</p>’; $content .= $copyright; } return $content; } add_filter( ‘the_content_feed’, ‘custom_add_rss_copyright_notice’ );






Add a “Popular Post” Label Based on Comment Count

/** * Add a “Popular” label to posts with many comments */ function custom_add_popular_post_label( $title, $post_id ) { if ( is_admin() || get_post_type( $post_id ) !== ‘post’ ) { return $title; } $comment_count = get_comments_number( $post_id ); if ( $comment_count >= 10 ) { $title .= ‘ <span class=”popular-post-label”>Popular</span>’; } return $title; } add_filter( ‘the_title’, […]


Add an “Updated Recently” Label to WordPress Posts

Steps Add the PHP code to your theme’s functions.php file or a PHP snippets plugin. Save and activate the snippet. Update any blog post. Posts updated within the last 7 days will display an Updated Recently label.


Proudly supported by