How To Highlight Search Results In WordPress
Adding the following snippet will let you highlight search results in WordPress.
1 2 3 4 5 6 |
<?php // Replace the_exerpt() with: $excerpt = get_the_excerpt(); $keys = explode(" ",$s); $excerpt = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">\0</strong>', $excerpt); echo $excerpt; |
Snippet Source/Credit: WPRecipes.com
How To Include Future Post In RSS Feed In WordPress
Adding the following snippet to your theme’s functions.php file will let you include future post in RSS feed in WordPress.
1 2 3 4 5 6 7 8 9 10 |
<?php /* Include published and future posts in rss feed. */ function FuturePostsFeed($query) { if ($query->is_feed) { $query->set('post_status','publish,future'); } return $query; } add_filter('pre_get_posts','FuturePostsFeed'); ?> |
Snippet Source/Credit: WP-Snippets.com
How To Post Classes For The Loop In WordPress
Adding the following snippet to your theme’s functions.php file will let you post classes for the loop in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php function additional_post_classes( $classes ) { global $wp_query; if( $wp_query->found_posts < 1 ) { return $classes; } if( $wp_query->current_post == 0 ) { $classes[] = 'post-first'; } if( $wp_query->current_post % 2 ) { $classes[] = 'post-even'; } else { $classes[] = 'post-odd'; } if( $wp_query->current_post == ( $wp_query->post_count - 1 ) ) { $classes[] = 'post-last'; } return $classes; } add_filter( 'post_class', 'additional_post_classes' ); ?> |
Snippet Source/Credit: WP-Snippets.com
How To Remove CSS Selector Attributes From WP-Nav Menu In WordPress
Adding the following snippet into your theme’s functions.php file will let you remove CSS selector attributes from WP-nav menu in WordPress.
1 2 3 4 5 6 |
<?php function remove_css_selector_attributes($input) { return preg_replace('/ (id|class)=\"(.*?)\"/', '', $input); } add_filter( 'wp_nav_menu', 'remove_css_selector_attributes' ); ?> |
Snippet Source/Credit: WP-Snippets.com
How To Remove Gallery Settings In WordPress
Adding the following snippets to your theme’s functions.php file will let you remove gallery settings in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php add_action( 'admin_head_media_upload_gallery_form', 'mfields_remove_gallery_setting_div' ); if( !function_exists( 'mfields_remove_gallery_setting_div' ) ) { function mfields_remove_gallery_setting_div() { print ' <style type="text/css"> #gallery-settings *{ display:none; } </style>'; } } ?> |
Snippet Source/Credit: mfields.org