WordPress Power Tips and Tricks 2016

WordPress Optimization by RankYa

WordPress no doubt is one of the best content management systems on the planet. Rise & popularity of WordPress can be seen in WordPress users produce about 59.3 million new posts each month and this number is growing exponentially. So knowing how to use the tool that your online business is built upon is only smart.

Let me showcase some of the tips and tricks and also the custom functions I gathered through optimizing Wordpress built sites. Caution: backup any file before you edit to avoid site breakage.

Custom WordPress Functions

How to Change the Default WordPress Avatar

Locate your functions.php file (you can do this either through Dashboard > Appearance > Editor > functions.php (if you’re using a child theme, then Select Theme to Edit option on top right hand side) and go towards the end of your function and insert

/**Custom Gravatar**/
function rankya_custom_avatar ($avatar_defaults) {
// Simply first upload an image to your media library for your custom avatar (size can be 90x90px or higher or lower)
// Then change the below image URL path to match your own custom avatar URL path
$rankyavatar = 'https://www.rankya.com/wp-content/uploads/2016/04/rankya_gravatar_icon_150x.png';
$avatar_defaults[esc_url($rankyavatar)] = "Custom Avatar";
return $avatar_defaults;
add_filter( 'avatar_defaults', 'rankya_custom_avatar' );

Once you insert this function and update functions.php go to Dashboard > Settings > Discussions > Default Avatar and select your new custom avatar.

Remove Head Scripts to Footer Section

Great for improving page load times and SEO if you make the default scripts and CSS files to be called in footer instead of the default <head> section. Here’s the WordPress actions to do this

function remove_head_scripts() {
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);
add_action( 'wp_enqueue_scripts', 'remove_head_scripts' );

Remove Dynamic CSS and JS Version Information

Depending on your WordPress setup, you may have dynamic CSS version information being blurted out, remove them using this function

function rankya_remove_version_for_cssjs( $source) {
if( strpos( $source, '?ver=' ) )
$source = remove_query_arg( 'ver', $source);
return $source;
add_filter( 'style_loader_src', 'rankya_remove_version_for_cssjs', 1000 );
add_filter( 'script_loader_src', 'rankya_remove_version_for_cssjs', 1000 );

Custom Comment Heading Message

Use this function to test different call to actions on comment headings. This changes the default comment reply text for better conversions

/**Custom Comment Heading**/
function rankya_comment_heading($defaults) {
$defaults['title_reply'] = 'Have Your Say! Comment';
$defaults['title_reply_to'] = 'Have Your Say. %s';
return $defaults;
add_filter('comment_form_defaults', 'rankya_comment_heading');

Enable Shortcode in Widget

By default, shortcodes in text widgets are not enabled in WordPress. However, since the text from a text widget runs through a filter called widget_text you can enable it
add_filter('widget_text', 'do_shortcode');

Create Shortcodes

At the end of the day, it can be difficult to blurt out certain HTML code as the formatting is removed for security reasons. But you use shortcodes to overcome this

function myshortcode(){
return 'Now you can use shortcodes for various reasons, including in posts, pages and widgets';
// To use it, simply paste this [insertmyshortcode]

Set HTML Editor as Default

Know bit about HTML? This will save you one click less when you want to create your next post, goes straight to HTMl editor instead of Visual Editor

add_filter( 'wp_default_editor', create_function('', 'return "html";') );

How About HTML5 and Structured Data?

Using ? If so, then you may find it difficult to add HTML5 content, particularly on hyperlinks as the formatting is removed on save (or visual editor switch). I came up with this solution

function rankya_tinymce_config( $init ) {
$valid_a = 'a[accesskey|charset|class|contenteditable|contextmenu|coords|dir|download|draggable|dropzone|hidden|href|hreflang|id|lang|media|name|rel|rev|shape|spellcheck|style|tabindex|target|title|translate|type|onclick|onfocus|onblur|itemprop]';
// Add to extended_valid_elements if it already exists
if ( isset( $init['extended_valid_elements'] ) ) {
$init['extended_valid_elements'] .= ',' . $valid_a;
} else {
$init['extended_valid_elements'] = $valid_a;
// Pass $init back to WordPress
return $init;
add_filter('tiny_mce_before_init', 'rankya_tinymce_config');

Change Image Quality

Although I actually wouldn’t recommend using this for most sites, you may depending on your WP setup find it of use.
//apply_filters ( 'jpeg_quality', int $quality, string $context )
//wordpress will still compress it, but this now means it will compress at the highest quality
//Source file: wp-includes/class-wp-image-editor.php default is 82
function rankya_jpeg_highest_quality( $quality, $context ) {
return 100;
add_filter( 'jpeg_quality', 'rankya_jpeg_highest_quality', 10, 2 );

So far I shared with you WordPress tips and tricks you can easily incorporate on your own WP setup, simply use any of these functions by first by making sure that you backup your current functions.php file and also make sure that you can access your web hosting account just in case something goes wrong so that you can restore the backup.

Video Lesson Showing How to Use These WordPress Function

Because to master WordPress, we must be brave with adding all these extra bits of code to really optimize sites built on WordPress Content Management System.

Got any comments? Interested in more powerful functions? Use the commenting system below. Thank you for sharing this blog post with others

Author: RankYa

RankYa: Online Entrepreneur, Web Developer, Google AdWords and Google Analytics Certified Professional. Specialist in: Structured Data, Microdata, Microformats, RDF, Schema.org Vocabulary, HTML5, WordPress optimization, Advanced Image Optimization, Google Webmaster Tools, Social Media Marketing, Facebook marketing and YouTube video ranking mastery. Latest Course The Art of 2016 SEO View all posts by

Have Your Say! Comment

Your email address will not be published. Required fields are marked *