How to Fix Underscore Theme Title Error with Theme-Check Plugin

Fix Underscore Theme Error with Theme-Check Plugin

If you are using a WordPress theme based on old “underscores” theme, when you try to check your theme using “Theme-Check” plugin you will see this message:

The <title> tags can only contain a call to wp_title(). Use the wp_title filter to modify the output

Look at the image:

Fix Underscore Theme Error with Theme-Check Plugin

You can fix this problem editing inc/extras.php file. Open extras.php and find this:

if ( ! function_exists( '_wp_render_title_tag' ) ) :
	/**
	 * Title shim for sites older than WordPress 4.1.
	 *
	 * @link https://make.wordpress.org/core/2014/10/29/title-tags-in-4-1/
	 * @todo Remove this function when WordPress 4.3 is released.
	 */
	function themeslug_render_title() {
		echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
	}
	add_action( 'wp_head', 'themeslug_render_title' );
endif;

Replace it with:

if ( ! function_exists( '_wp_render_title_tag' ) ) :
	function themeslug_render_title() {
		?>
		<title><?php wp_title( '|', true, 'right' ); ?></title>
		<?php
	}
	add_action( 'wp_head', 'themeslug_render_title' );
endif;

Save extra.php file and check your theme again with “Theme-Check” plugin. Above error message will not be displayed again.

How to Add Hotlink Protection using .htaccess in WordPress

Adding this snippet into your .htaccess file, you will be able to add hotlink protection to your files. It will help you to save your site bandwidth.

RewriteCond %{HTTP_REFERER} !^http://example.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://example.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

Here hotlink has been added to image files (.jpg, .jpeg, .gif, .png, .bmp). You can add or remove more file types.

RewriteCond %{HTTP_REFERER} !^http://example.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://example.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|zip)$ - [F,NC]

Remember to replace “example.com” with your domain name. Look at the example below:

Add Hotlink Protection using htaccess in WordPress

How to Block Visitors using .htaccess in WordPress

To block a visitor in your WordPress site using this method, you need to know the IP address of that visitor. Adding this snippet into your .htaccess file, that user will see a error message when trying to access into your site.

<Limit GET POST PUT>
order allow,deny
allow from all
deny from x.x.x.x
</Limit>

Remember to replace “x.x.x.x” with the IP address of the visitor you want to block.

If you need to block more than one visitor, then add their IP addresses like this:

<Limit GET POST PUT>
order allow,deny
allow from all
deny from x.x.x.x
deny from y.y.y.y
deny from z.z.z.z
</Limit>

How to Hide Upgrade Notice from WordPress Dashboard

Hide Upgrade Notice from WordPress Dashboard

When a new version of WordPress available, a notification will be displayed in WordPress admin area similar to this.

WordPress x.x.x is available! Please update now.

Hide Upgrade Notice from WordPress Dashboard

Some people like to see this WordPress update notification, but others don’t.

Adding this code snippet to your theme’s functions.php file, upgrade notification will be removed from WordPress admin dashboard.:

function nwt_hide_update_notice() {
    remove_action( 'admin_notices', 'update_nag', 3 );
}
add_action('admin_menu','nwt_hide_update_notice');

How to Hide/Remove Admin Toolbar Bar in WordPress

WordPress automatically shows an admin toolbar at the top of the page for logged-in users. Many users do not like to this WordPress admin toolbar bar because it is not displaying well with their WordPress themes.

Add the code given below into your functions.php file to prevent that toolbar from displaying:

add_filter('show_admin_bar', '__return_false');

Alternate code:

function nwt_remove_admin_bar(){
	return false;
}
add_filter( 'show_admin_bar' , 'nwt_remove_admin_bar');

How to Protect wp-config.php with .htaccess

Adding below snippet into your .htaccess file will prevent access to your wp-config.php file:

<Files wp-config.php>
 Order Allow,Deny
 Deny from all
</Files>