Remove Query strings and add featured images in WordPress feeds

A small post today to share with you a small tips to remove all the queries strings from WordPress static assets, and also to add featured images of your posts in the WordPress feeds.

  1. Go into your WordPress dashboard > Appearance > Editor
  2. Then find the file functions.php of your theme
  3. Add this code at the end of  functions.php


//remove queries from static assets
function _remove_script_version( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

// Include thumbnails is the RSS feed
function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) .
'</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');

You can now try with GTMetrix.com if you have succefully remove the query strings. For the feed, you can test it with any RSS feed reader. Your WordPress feed are normally available at http://yourdomain.com/feed/.