Remove image sizes in WordPress

/** * Function to Remove image size. * @param [string] $size */ function remove_image_size_by_size($size) { $dimension = explode(‘x’, $size); global $_wp_additional_image_sizes; foreach ($_wp_additional_image_sizes as $key => $single) { if ($single[‘width’] == $dimension[0] && $single[‘height’] == $dimension[1]) { remove_image_size($key); break; }

Handful WP-CLI Tricks

Delete posts based on search # Spaces needs replace with + (plus sign) # Eg: hello+world wp post delete $(wp post list –post_type=’post’ –s=’keyword+here’ –format=ids) –force

Tweaking OneSignal WordPress Plugin

/** * Send push based on last active time (Intelligent Delivery). */ add_filter( ‘onesignal_send_notification’, function( $fields ) { $fields[‘delayed_option’] = ‘last-active’; return $fields; }); /** * Always set notification unchecked in post editor. */ add_filter( ‘onesignal_meta_box_send_notification_checkbox_state’, ‘__return_false’ ); /** *

Tweaking WordPress

/** * Logged in for 1 year. */ add_filter( ‘auth_cookie_expiration’, function() { return YEAR_IN_SECONDS; });

Clear cache in WP Rocket when post permalink (slug) changes

To learn more about the issue: Fix: // Fires before an existing post is updated in the database. add_action( ‘pre_post_update’, function( $post_ID, $data ) { // Compare slug, if changed clear cache. if ( get_post_field( ‘post_name’, $post_ID ) !=

Use CDN with WP Offload Media

add_filter(‘as3cf_get_attachment_url’, function($url) { // Regex matches both http and https. $url = ‘’ . preg_replace(‘#^https?://#’, ”, $url); return $url; }); More hooks of WP Offload Media can be found on amazon-s3-and-cloudfront-tweaks.php

Use Rocket-Nginx under RunCloud

Login as root then enter following commands. cd /etc/nginx-rc git clone cd rocket-nginx cp rocket-nginx.ini.disabled rocket-nginx.ini php rocket-parser.php As of version 2.1.1 there is a typo in the rocket-nginx.ini , change media_header to medias_header My template: Create file {app-name}.location.main-before.rocket.conf

Optimal Settings & Tweaking UpdraftPlus

Optimal Settings: Untick ❌ -> UpdraftPlus Automatic Backups Untick ❌ -> Automatic updates Tick ✅ -> Backup more databases Tick ✅ -> Delete local backup Tweaking: Add below codes to: updraftplus.php /* Disable top admin bar */ defined( ‘UPDRAFTPLUS_ADMINBAR_DISABLE’ )

Disable cURL SSL verification in WordPress

/** * Don’t verify SSL certificates */ add_action( ‘http_api_curl’, function( $handle ) { curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, false ); });

Use WP Smush without slowing down WordPress

I use WP Smush to compress images in WordPress. But lately the plugin became extremely slow because of excessive database queries. The media library takes 10 seconds to open while the plugin is active but takes only 2 seconds when

WP Rocket Hooks

after_rocket_clean_post action is fired after clear cache of a post. add_action( ‘after_rocket_clean_post’, function( $post ) { if ( $post->post_name == ‘foo’ ) { rocket_clean_files( ‘’ ); } }); after_rocket_clean_domain action is fired after clear cache of whole domain (clear all

WP Smush using WP-CLI

If you use WP Smush then you should know that you can use it via WP-CLI too. This feature became available since the version 3.1 Here are some commands: /** * Optimize image. * * ## OPTIONS * * [–type=<type>]

Remove any action or filter in WordPress

Sometimes we need to remove actions or filters added via Themes or Plugins. To remove a action or filter check’s guide. But sometimes that is not enough, sometimes some hooks are too stubborn to remove. In that case use

Delete comment replies when deleting comment in WordPress

By default when a comment is deleted, WordPress does not delete the replies of that comment. With this function whenever a comment is deleted, its replies will be automatically deleted. /** * Delete comment replies when deleting comment. */ add_action(