WordPress Code Snippet

This page contains all the helpful and working code snippets for WordPress performance and security optimization. You can just simply copy and paste to your WordPress site. Please make sure you are using WordPress Child Theme before you start using code snippets from here.

To display Breadcrumbs from Yoast SEO Plugin  at WordPress site, add this below code in theme header.php file.

<!-- YOAST SEO Plugin Breadcrumbs -->
if ( function_exists('yoast_breadcrumb')) {
yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );}

Add this below CSS Codes in style.css file

Theme Name: Child Theme of 2015
Author: BN Web Design
Author URI: https://www.bnwebdesign.com/
Description: Tweaking WordPress 2015 theme.
Template: twentyfifteen

Add this below code in functions.php file.

    Loads parent and child  stylesheet
function load_theme_stylesheet() {
  wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
  wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css' );
add_action( 'wp_enqueue_scripts', 'load_theme_stylesheet' );

Add this below code in functions.php file to remove Gutenberg completely from WordPress Twenty Nineteen Theme.

// Disable Gutenberg
add_filter('use_block_editor_for_post', '__return_false', 10);

Add this below code at .htaccess file to Secure WordPress Login Page by IP address

# Secure WordPress Login Page by IP Address
<Files wp-login.php>
order deny,allow
Deny from all
# Change below IP Address to Allow Access
allow from XXX.XXX.XXX.XXX

Add this below 3 blocks code inside functions.php file

Remove WordPress Version

    Remove version from head
remove_action('wp_head', 'wp_generator');

Remove WordPress Version from RSS

    Remove version from rss
function remove_feed_generator() {
return '';
add_filter('the_generator', 'remove_feed_generator');

Remove WordPress Version from Style sheet and JavaScript

    Remove version from scripts and styles
function remove_version_scripts_styles($src) {
	if (strpos($src, 'ver=')) {
		$src = remove_query_arg('ver', $src);
	return $src;
add_filter('style_loader_src', 'remove_version_scripts_styles', 9999);
add_filter('script_loader_src', 'remove_version_scripts_styles', 9999);