Blocking search from bots

add_action(‘pre_get_posts’, function($query) { if ($query->is_search() && !is_admin()) { $referer = wp_get_referer(); $site_url = get_site_url(); if (empty($referer) || strpos($referer, $site_url) !== 0) { // Block the request early to save CPU header(‘HTTP/1.1 403 Forbidden’); exit; } } });Continue reading

WordPress Post Views Counter Function

function wpb_set_post_views($postID) { $count_key = ‘wpb_post_views_count’; $count = get_post_meta($postID, $count_key, true); if($count==”){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, ‘0’); }else{ $count++; update_post_meta($postID, $count_key, $count); } } //Get rid of prefetching to keep the count accurate remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10,…Continue reading

Disable Inspector Tabs

add_filter( ‘block_editor_settings_all’, function ( $settings ) { if ( ! isset( $settings[‘blockInspectorTabs’] ) ) { $settings[‘blockInspectorTabs’] = array(); } $settings[‘blockInspectorTabs’] = array_merge( $settings[ ‘blockInspectorTabs’ ], array( ‘default’ => false, // Disables for all blocks. ), ); return $settings; } );Continue reading

Disable default WordPress image sizes

// Disable default WordPress image sizes add_filter(‘intermediate_image_sizes’, ‘__return_empty_array’); // Disable large scaled image size add_filter(‘big_image_size_threshold’, ‘__return_false’); // Disable WooCommerce image sizes and prevent WooCommerce from regenerating sizes add_action(‘after_setup_theme’, function () { // WooCommerce image sizes remove_image_size(‘woocommerce_thumbnail’); remove_image_size(‘woocommerce_single’); remove_image_size(‘woocommerce_gallery_thumbnail’); // Clear…Continue reading