Doc WordPress WordPress Tricks, Tips & Snippets

12Oct/150

Disable automatic redirect to site url

By default WordPress redirects incoming links automatically to the proper URL based on the site url, e.g. it would redirect incorrect incoming "www." URLs automatically to the correct form, as set in the site url setting. For example: when a requested URL is "http://yourdomain.com/whatever/" but the site-url is set as "http://www.yourdomain.com" WordPress will automatically redirect the visitor to "http://www.yourdomain.com/whatever/".

This is a good thing as search engines consider www. and non-www. as different URLs and this would otherwise lead to duplicate content. But should you for whatever reason wish to disable this behaviour you can easily do so by just adding this snippet to your theme's function.php:


remove_action('template_redirect', 'redirect_canonical');

Please note: this will also disable canonical redirects!

10Oct/150

Remove unnecessary stuff from WordPress header

By default WordPress adds quite some meta junk to your site's <head>. Luckily for us these can easily be disabled without the need to install a plugin for this (remember: the less plugins the better). Just add this to your website's functions.php (found in your theme folder):


remove_action('wp_head', 'wp_generator'); // remove wp version header
remove_action('wp_head', 'wlwmanifest_link'); // remove MS-live writer
remove_action('wp_head', 'rsd_link'); // remove Really Simple Discovery
remove_action( 'wp_head', 'feed_links_extra', 3 ); // remove Comments Feed

21Sep/150

Remove “#more-123” anchor from “Read more” links

By default WordPress automatically adds "#more-123" anchor links to the "Read more" links on post excerpts on all overview pages, causing the new page to jump down to that anchor once it has loaded. This behaviour might not be wanted and it is easy to fix.

Just add this to your theme's functions.php file:

function remove_more_jump_link($link) {
	$offset = strpos($link, '#more-');
	if ($offset) {
		$end = strpos($link, '"',$offset);
	}
	if ($end) {
		$link = substr_replace($link, '', $offset, $end-$offset);
	}
	return $link;
}

add_filter('the_content_more_link', 'remove_more_jump_link');