Remove Dashboard widgets

function snipjar_clean_wp_dashboard()
{
    remove_action("welcome_panel", "wp_welcome_panel");
    remove_meta_box("dashboard_primary", "dashboard", "side");
    remove_meta_box("dashboard_secondary", "dashboard", "side");
    remove_meta_box("dashboard_quick_press", "dashboard", "side");
    remove_meta_box("dashboard_recent_drafts", "dashboard", "side");
    remove_meta_box("dashboard_php_nag", "dashboard", "normal");
    remove_meta_box("dashboard_browser_nag", "dashboard", "normal");
    remove_meta_box("dashboard_site_health", "dashboard", "normal");
    remove_meta_box("health_check_status", "dashboard", "normal");
    remove_meta_box("dashboard_activity", "dashboard", "normal");
    remove_meta_box("dashboard_right_now", "dashboard", "normal");
    remove_meta_box("network_dashboard_right_now", "dashboard", "normal");
    remove_meta_box("dashboard_recent_comments", "dashboard", "normal");
    remove_meta_box("dashboard_incoming_links", "dashboard", "normal");
    remove_meta_box("dashboard_plugins", "dashboard", "normal");
}
add_action("wp_dashboard_setup", "snipjar_clean_wp_dashboard");

Hide admin notices for everyone except a specific username

function hide_admin_notices_except_specific_admin()
{
    //Checking if user is on an admin page
    if (is_admin()) {
        //Getting the current user object
        $current_user = wp_get_current_user();
        //Checking if the current user has the 'administrator' role and their username is not 'specific_username'
        if (
            in_array("administrator", $current_user->roles) &&
            $current_user->user_login !== "INSERT_USERNAME"
        ) {
            //Removing all actions of 'admin_notices'
            remove_all_actions("admin_notices");
        }
    }
}
//Calling the function on 'admin_init' action
add_action("admin_init", "hide_admin_notices_except_specific_admin");

Remove Comments from Frontend and Admin Area

add_action('admin_init', function () {
    // Redirect any user trying to access comments page
    global $pagenow;

    if ($pagenow === 'edit-comments.php') {
        wp_safe_redirect(admin_url());
        exit;
    }

    // Remove comments metabox from dashboard
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');

    // Disable support for comments and trackbacks in post types
    foreach (get_post_types() as $post_type) {
        if (post_type_supports($post_type, 'comments')) {
            remove_post_type_support($post_type, 'comments');
            remove_post_type_support($post_type, 'trackbacks');
        }
    }
});

// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);

// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);

// Remove comments page in menu
add_action('admin_menu', function () {
    remove_menu_page('edit-comments.php');
});

// Remove comments links from admin bar
add_action('init', function () {
    if (is_admin_bar_showing()) {
        remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
    }
});

Media library Alt text column in list view

function add_alt_text_column($columns) {
    $columns['alt_text'] = 'Alt Text';
    return $columns;
}
add_filter('manage_media_columns', 'add_alt_text_column');

// Display alt text with colored dot in the custom column
function display_alt_text_column($column_name, $attachment_id) {
    if ($column_name === 'alt_text') {
        $alt_text = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
        $file_type = wp_check_filetype(wp_get_attachment_url($attachment_id));
        $image_types = array('jpg', 'jpeg', 'png', 'webp', 'avif', 'gif', 'svg');

        if (in_array($file_type['ext'], $image_types)) {
            if (!empty($alt_text)) {
                echo esc_html($alt_text);
            } else {
                echo '<div style="display:flex;align-items:center;"><p style="margin:0;color: red;font-size: 48px;">&bull;</p><p style="margin-top:1.1rem;padding-left:1rem;font-weight:700;">Missing Alt text!</p></div>';
            }
        } else {
            echo '<div style="display:flex;align-items:center;"><p style="margin:0;color: royalblue;font-size: 48px;">&bull;</p><p style="margin-top:1.1rem;padding-left:1rem;font-weight:700;">N/A</p></div>';
        }
    }
}
add_action('manage_media_custom_column', 'display_alt_text_column', 10, 2);

Show post thumbnails in RSS Feed

function snipjar_feed_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'snipjar_feed_post_thumbnail');
add_filter('the_content_feed', 'snipjar_feed_post_thumbnail');

Allow contributors to upload images

if ( current_user_can('contributor') && !current_user_can('upload_files') )
     add_action('admin_init', 'allow_contributor_uploads');      
     function allow_contributor_uploads() {
          $contributor = get_role('contributor');
          $contributor->add_cap('upload_files');
     }

Apply a coupon depending on cart weight 

add_action( 'woocommerce_before_cart', 'snipjar_apply_coupon_cart_weight' );

function snipjar_apply_coupon_cart_weight() {
	$coupon_code = 'snipdeal';
	// if cart content weight is more than 15kg
	if( 15 < WC()->cart->get_cart_contents_weight() ) {
		if( ! WC()->cart->has_discount( $coupon_code ) ) {
			WC()->cart->apply_coupon( $coupon_code );
		}
	} else {
		WC()->cart->remove_coupon( $coupon_code );
		WC()->cart->calculate_totals();
	}
}

Apply a coupon depending on cart subtotal 

add_action( 'woocommerce_before_cart', 'snipjar_apply_coupon_cart_subtotal' );

function snipjar_apply_coupon_cart_subtotal() {
	$coupon_code = 'snipdeal';
	// if cart subtotal is more than 10,000
	if( 10000 < WC()->cart->get_subtotal() ) {
		if( ! WC()->cart->has_discount( $coupon_code ) ) {
			WC()->cart->apply_coupon( $coupon_code );
		}
	} else {
		WC()->cart->remove_coupon( $coupon_code );
		WC()->cart->calculate_totals();
	}
}