Allow SVG Files Upload

Add support for SVG files to be uploaded in WordPress media.

Use Snippet
php
<?php
/**
 * Allow SVG uploads for administrator users.
 *
 * @param array $upload_mimes Allowed mime types.
 *
 * @return mixed
 */
add_filter(
	'upload_mimes',
	function ( $upload_mimes ) {
		// By default, only administrator users are allowed to add SVGs.
		// To enable more user types edit or comment the lines below but beware of
		// the security risks if you allow any user to upload SVG files.
		if ( ! current_user_can( 'administrator' ) ) {
			return $upload_mimes;
		}
		$upload_mimes['svg']  = 'image/svg+xml';
		$upload_mimes['svgz'] = 'image/svg+xml';
		return $upload_mimes;
	}
);
/**
 * Add SVG files mime check.
 *
 * @param array        $wp_check_filetype_and_ext Values for the extension, mime type, and corrected filename.
 * @param string       $file Full path to the file.
 * @param string       $filename The name of the file (may differ from $file due to $file being in a tmp directory).
 * @param string[]     $mimes Array of mime types keyed by their file extension regex.
 * @param string|false $real_mime The actual mime type or false if the type cannot be determined.
 */
add_filter(
	'wp_check_filetype_and_ext',
	function ( $wp_check_filetype_and_ext, $file, $filename, $mimes, $real_mime ) {
		if ( ! $wp_check_filetype_and_ext['type'] ) {
			$check_filetype  = wp_check_filetype( $filename, $mimes );
			$ext             = $check_filetype['ext'];
			$type            = $check_filetype['type'];
			$proper_filename = $filename;
			if ( $type && 0 === strpos( $type, 'image/' ) && 'svg' !== $ext ) {
				$ext  = false;
				$type = false;
			}
			$wp_check_filetype_and_ext = compact( 'ext', 'type', 'proper_filename' );
		}
		return $wp_check_filetype_and_ext;
	},
	10,
	5
);
WPCode Team
3.6k

Remove WordPress Version Number

Hide the WordPress version number from your site's frontend and feeds.

Use Snippet
php
<?php
add_filter('the_generator', '__return_empty_string');
WPCode Team
3.0k

Disable Gutenberg Editor (use Classic Editor)

Switch back to the Classic Editor by disablling the Block Editor.

Use Snippet
php
<?php
add_filter('gutenberg_can_edit_post', '__return_false', 5);
add_filter('use_block_editor_for_post', '__return_false', 5);
WPCode Team
2.6k

Disable XML-RPC

On sites running WordPress 3.5+, disable XML-RPC completely.

Use Snippet
php
<?php
add_filter( 'xmlrpc_enabled', '__return_false' );
WPCode Team
2.0k

Disable Widget Blocks

Use the classic interface instead of Blocks to manage Widgets.

Use Snippet
php
<?php
add_filter( 'use_widgets_block_editor', '__return_false' );
WPCode Team
1.7k

Disable The WP Admin Bar

Hide the WordPress Admin Bar for all users in the frontend.

Use Snippet
php
<?php
/* Disable WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );
WPCode Team
1.4k

Disable Automatic Updates Emails

Stop getting emails about automatic updates on your WordPress site.

Use Snippet
php
<?php
// Disable auto-update emails.
add_filter( 'auto_core_update_send_email', '__return_false' );
// Disable auto-update emails for plugins.
add_filter( 'auto_plugin_update_send_email', '__return_false' );
// Disable auto-update emails for themes.
add_filter( 'auto_theme_update_send_email', '__return_false' );
WPCode Team
1.4k

Disable Automatic Updates

Use this snippet to completely disable automatic updates on your website.

Use Snippet
php
<?php
// Disable core auto-updates
add_filter( 'auto_update_core', '__return_false' );
// Disable auto-updates for plugins.
add_filter( 'auto_update_plugin', '__return_false' );
// Disable auto-updates for themes.
add_filter( 'auto_update_theme', '__return_false' );
WPCode Team
1.1k

Disable Attachment Pages

Hide the Attachment/Attachments pages on the frontend from all visitors.

Use Snippet
php
<?php
add_action(
	'template_redirect',
	function () {
		global $post;
		if ( ! is_attachment() || ! isset( $post->post_parent ) || ! is_numeric( $post->post_parent ) ) {
			return;
		}
		// Does the attachment have a parent post?
		// If the post is trashed, fallback to redirect to homepage.
		if ( 0 !== $post->post_parent && 'trash' !== get_post_status( $post->post_parent ) ) {
			// Redirect to the attachment parent.
			wp_safe_redirect( get_permalink( $post->post_parent ), 301 );
		} else {
			// For attachment without a parent redirect to homepage.
			wp_safe_redirect( get_bloginfo( 'wpurl' ), 302 );
		}
		exit;
	},
	1
);
WPCode Team
1.1k

Enable Shortcode Execution in Text Widgets

Extend the default Text Widget with shortcode execution.

Use Snippet
php
<?php
add_filter( 'widget_text', 'do_shortcode' );
WPCode Team
1.1k

Disable WordPress REST API

Easily disable the WP REST API on your website with this snippet.

Use Snippet
php
<?php
add_filter(
	'rest_authentication_errors',
	function ( $access ) {
		return new WP_Error(
			'rest_disabled',
			__( 'The WordPress REST API has been disabled.' ),
			array(
				'status' => rest_authorization_required_code(),
			)
		);
	}
);
WPCode Team
1.0k

Disable RSS Feeds

Turn off the WordPress RSS Feeds for your website with 1 click.

Use Snippet
php
<?php
/**
 * Display a custom message instead of the RSS Feeds.
 *
 * @return void
 */
function wpcode_snippet_disable_feed() {
	wp_die(
		sprintf(
			// Translators: Placeholders for the homepage link.
			esc_html__( 'No feed available, please visit our %1$shomepage%2$s!' ),
			' <a href="' . esc_url( home_url( '/' ) ) . '">',
			'</a>'
		)
	);
}
// Replace all feeds with the message above.
add_action( 'do_feed_rdf', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_rss', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_rss2', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_atom', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_rss2_comments', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_atom_comments', 'wpcode_snippet_disable_feed', 1 );
// Remove links to feed from the header.
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
WPCode Team
900+

Change Admin Panel Footer Text

Display custom text in the admin panel footer with this snippet.

Use Snippet
php
<?php
add_filter(
	'admin_footer_text',
	function ( $footer_text ) {
		// Edit the line below to customize the footer text.
		$footer_text = 'Powered by <a href="https://www.wordpress.org" target="_blank" rel="noopener">WordPress</a> | WordPress Tutorials: <a href="https://www.wpbeginner.com" target="_blank" rel="noopener">WPBeginner</a>';
		
		return $footer_text;
	}
);
WPCode Team
900+

Change "Howdy Admin" in Admin Bar

Customize the "Howdy" message in the admin bar.

Use Snippet
php
<?php
function wpcode_snippet_replace_howdy( $wp_admin_bar ) {
	// Edit the line below to set what you want the admin bar to display intead of "Howdy,".
	$new_howdy = 'Welcome,';
	$my_account = $wp_admin_bar->get_node( 'my-account' );
	$wp_admin_bar->add_node(
		array(
			'id'    => 'my-account',
			'title' => str_replace( 'Howdy,', $new_howdy, $my_account->title ),
		)
	);
}
add_filter( 'admin_bar_menu', 'wpcode_snippet_replace_howdy', 25 );
WPCode Team
700+

Hide Login Errors in WordPress

Improve safety by hiding the specific login error information.

Use Snippet
php
<?php
add_filter(
	'login_errors',
	function ( $error ) {
		// Edit the line below to customize the message.
		return 'Something is wrong!';
	}
);
WPCode Team
600+
1 2 3 4