WordPress Hacks and Tricks

How to Remove WordPress Admin Bar

I never use the WP Admin Bar and have this code as part of my WordPress themes.

If your theme doesn’t already have the option to disable the WordPress Admin Bar add this code to your functions.php file.

<?php
add_filter('show_admin_bar', '__return_false');
?>

How to Add Custom Content to WordPress Login Page

Want to display a customized message as you login to WordPress, add the following code to your functions.php file.

<?php function str_custom_login( $message ) {
if ( empty($message) ){
return '<p class="message">Totally Rad Message Here...</p>';
} else {
return $message;
}
} 
add_filter( 'login_message', 'str_custom_login' );
?>

WordPress Hacks

Cleaning up the wp_head() Output

In my Stallion SEO WordPress and Stallion Responsive Themes there’s options to disable items from the head of a page. For your average WordPress site you should NOT remove them all, in my SEO themes the first options are by default set to OFF (remove the code) and the remaining set to ON (do not remove the code).

WordPress Hack add_filter wp_head
Click the image to the right to see the Stallion Responsive options page with defaults set.

For example you do want to turn off the wp_generator (adds nothing useful), but should NOT turn off rel_canonical. Here’s the default options from the Stallion Responsive theme and what they do:

wp_generator Off: Hides WordPress version number security issue (OFF).
wp_shortlink_wp_head Off: Removes Shortlinks (OFF).
start_post_rel_link Off: Removes relational link to first ever post (OFF).
adjacent_posts_rel_link_wp_head Off: Removes relational link to Previous and Next posts (OFF).
index_rel_link Off: Removes relational link to home (OFF).
parent_post_rel_link Off: Removes relational link to Parent Page (OFF).
wlwmanifest_link Off: Removes the Windows Live Writer link (OFF).
rsd_link Off: Removes Really Simple Discovery Links (OFF).
automatic-feed-links Off: Removes Automatic Feed Links (OFF).
wp_no_robots Off: Removes noindex,nofollow robots meta tag (OFF)

wp_enqueue_scripts Off: Prevents WordPress from adding javascript to a site. (ON).
wp_print_head_scripts Off: Prevents plugins from adding javascript to a site. (ON).
wp_print_styles Off: Prevents plugins from adding stylesheets to a site. (ON).
feed_links Off: Removes main RSS feed links (ON).
feed_links_extra Off: Removes extra RSS feed links (ON).
rel_canonical Off: Removes canonical URLs (ON).

And the Corresponding WordPress code for turning the code off.

The first 9 are safe for most WordPress blogs.

<?php remove_action('wp_head', 'wp_generator'); ?>
<?php remove_action('wp_head', 'wp_shortlink_wp_head'); ?>
<?php remove_action('wp_head', 'start_post_rel_link'); ?>
<?php remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); ?>
<?php remove_action('wp_head', 'index_rel_link'); ?>
<?php remove_action('wp_head', 'parent_post_rel_link', 10, 0); ?>
<?php remove_action('wp_head', 'wlwmanifest_link'); ?>
<?php remove_action('wp_head', 'rsd_link'); ?>
<?php remove_action('wp_head', 'wp_no_robots'); ?>

Do Not Use the code below unless you have a good reason.

<?php remove_action('wp_head', 'wp_enqueue_scripts', 1); ?>
<?php remove_action('wp_head', 'wp_print_head_scripts', 9); ?>
<?php remove_action('wp_head', 'wp_print_styles', 8); ?>
<?php remove_action('wp_head', 'feed_links', 2); ?>
<?php remove_action('wp_head', 'feed_links_extra', 3); ?>
<?php remove_action('wp_head', 'rel_canonical'); ?>
<?php add_theme_support('automatic-feed-links'); ?>

Remember the above code is built into Stallion WordPress SEO and Stallion Responsive, a small amount of it (the ones that should be set to off) is also part of Talian 5.5. So if you are one of my theme users, do not add this code to Stallion or Talian.

David Law

David Law > AKA SEO Dave
*
: Experienced WordPress SEO Expert, Internet Marketer, Developer of the Best SEO Package Stallion Responsive WP SEO Theme (tested to WordPress 4.8 June 2017) and Nice Guy :-)

Website - SEO Tutorial for WordPress