Select Page

Output additional image sizes on the frontend of WordPress

Use this to find all the additional image sizes your site is using

/* Output all image sizes on the frontend
---------------------------------------------------------------------------------------------------- */	 
add_action('init', 'get_all_image_sizes');

function get_all_image_sizes(){
    global $_wp_additional_image_sizes; 
    print '<pre>'; 
    print_r( $_wp_additional_image_sizes ); 
    print '</pre>';

Disable Divi Custom Post Type CSS file

Add this to your functions files to disable/remove the Divi CPT CSS file from being used.

/* Disable Divi CPT CSS */
function disable_cptdivi() {
	remove_action( 'wp_enqueue_scripts', 'et_divi_replace_stylesheet', 99999998 );
add_action('init', 'disable_cptdivi');
add_filter( 'woocommerce_product_tabs', 'bbloomer_remove_product_tabs', 9999 );

How to enable WordPress debug mode and log errors

To enable error logging, create an empty file named “php-errors.log”. Place it in a directory that is not publicly accessible (preferably outside your web root) and ensure it is writable by the web server. Then add the following code to wp-config.php:

@ini_set('log_errors', 'On');
@ini_set('error_log', '/full/path/to/php-errors.log');

By default, only fatal errors and warnings will be logged. To also log notices and other messages, enable the WP_DEBUG option by adding this code:

//Report all types of errors.
define('WP_DEBUG', true);
//Don't show errors to site visitors.
define('WP_DEBUG_DISPLAY', false);

Remove query strings from static resources in WordPress

Use this to remove query strings from static resources in WordPress

// Remove query strings from static resources
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 );

Leverage Browser Caching in WordPress via .htaccess

Add this to your .htacess to Leverage Browser Caching

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"

ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"

<FilesMatch "\\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE

<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

How to delete all images from your WordPress site

Use this SQL to remove all images/documents/etc from your media library

1 – Run these in phpmyadmin

DELETE FROM wp_postmeta
WHERE post_id IN
FROM wp_posts
WHERE post_type = 'attachment'
DELETE FROM wp_posts WHERE post_type = 'attachment'

2 – Manually delete all the year folders in the /wp-content/uploads folder.

Hide premium WordPress theme notifications

Most premium themes ask you to install additional plugins however if you dont install all of the plugins it recommends and keep them activated you will see a warning at the top of the admin area which comes back even if you close it.

If you add this code to your functions file it will hide the box. You might need to change the id of setting-error-tgmpa however on two sites I am building this is the same id.

//hide update notifications
add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
  echo '<style>
    #setting-error-tgmpa {

Hide menu items in the WordPress Admin Area

Use this to hide menu items in the WordPress admin area that you do not use.

function remove_menus_links(){
 remove_menu_page( 'edit.php?post_type=portfolio' );
 remove_menu_page( 'edit.php?post_type=team' );
 remove_menu_page( 'edit.php?post_type=clients' );
 remove_menu_page( 'edit.php?post_type=agni_slides' );
add_action( 'admin_menu', 'remove_menus_links' );

Set a maximum image upload size in WordPress

This can be used to set a maximum image upload size in WordPress, this helps to stop clients uploading large image files.

This example is 1.5mb

//limit image file size to 1.5mb
function whero_limit_image_size($file) {
// Calculate the image size in KB
$image_size = $file['size']/1024;
// File size limit in KB
$limit = 1500;
// Check if it's an image
$is_image = strpos($file['type'], 'image');
if ( ( $image_size > $limit ) && ($is_image !== false) )
        $file['error'] = 'Your picture is too large. It has to be smaller than '. $limit .'KB';
return $file;
add_filter('wp_handle_upload_prefilter', 'whero_limit_image_size');

Move WooCommerce category description up to be full width

This will move the WooCommerce category description up to be full width instead of in the right hand column.

//move cat description up the page
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_before_main_content', 'woocommerce_taxonomy_archive_description', 2 );