7 WordPress Snippets to Enhance Your Themes

7 WordPress Snippets to Enhance Your Themes Tutorials

Whether it’s in-depth functionality or a bigger thumbnail size, WordPress has you covered. It’s such a flexible CMS that the limits almost feel endless. I’ve searched through a large handful of my past and current projects, as well as looking through sites like Stack Overflow and more to find 7 of the best WordPress snippets for you to use on your WordPress themes.

Sometimes code snippets aren’t enough to add that extra bit of functionality that you’re after. In those cases I advise looking at some helpful plugins as they tend to be more thoroughly tested by the developer and the community.

How to use: To use the following WordPress snippets just copy and paste them into your theme’s functions.php file.

What handy WordPress snippets are you using? Let me know in the comments.

1.) Add Custom Links to Profile Page

On the profile editor screen of WordPress you have options for your email address and website, but what if you want to add links to your YouTube, Instagram, Dribbble or other accounts? With this WordPress snippet you can add as many as you want!

function add_to_author_profile($options) {
	$options['youtube_url'] = 'YouTube';
	$options['dribbble_url'] = 'Dribbble';
	$options['instagram_url'] = 'Instagram';

	return $options;

add_filter('user_contactmethods', 'add_to_author_profile', 10, 1);

To display your content you need to use the_author_meta(); template tag, like so:

<?php the_author_meta('youtube_url'); ?>

2.) Add Custom Post Types to Main Loop

When you create a custom post type it doesn’t show up in the main WordPress loop by default. With this WordPress snippet you can have your custom post type show up in the main loop with everything else.

function add_to_main_loop($query) {
	if ($query->is_main_query()) {
		$query->set('post_type', array('post','POST_TYPE'));

add_action('pre_get_posts', 'add_to_main_loop');

3.) Change Excerpt Length and ‘More’ Text

Nobody wants an excerpt that’s too short, too long or ends with […]. Below are two quick WordPress snippets to change the length and remove the trailing […]:

//----- Change Length
function modify_excerpt_length($length) {
	return 30;

add_filter('excerpt_length', 'modify_excerpt_length', 999);

//----- Change '[...]' Text
function modify_excerpt_more($more) {
	return '...';

add_filter('excerpt_more', 'modify_excerpt_more');

4.) Limit Search to ONLY Posts

It’s frustrating when you’re running a blog and you want people to have the ability of searching only the posts on your site, not pages as well. Here’s a WordPress snippet that limits search to ONLY posts:

function modify_search_filter($query) {
	if ($query->is_search) {
		$query->set('post_type', 'post');

	return $query;


5.) Enable HTML5 Output

If you’re a modern-day web design or developer, which this site was made for, you’ll want some shiny new HTML5 outputted from WordPress by default. Here’s a WordPress snippet to do just that:


6.) Remove Toolbar Unless Admin

If you run a community site where people can sign up for an account and you’re running a plugin like Restrict Content Pro, when a new user registers they automatically get the WordPress toolbar at the top of your site. This can be annoying because it makes your site appear less professional if users can see the (albeit limited) WordPress backend. With this WordPress snippet you can remove the default toolbar unless you have an account as an Admin:

function remove_admin_bar() {
	if (!current_user_can('administrator') && !is_admin()) {

add_action('after_setup_theme', 'remove_admin_bar');

7.) Redirect After Registration

With this WordPress snippet, when people register on your site you can specify exactly where they’re taken, perhaps a custom designed account page or an exclusive freebie for signing up. Here’s how to do just that:

function registration_redirect(){
	return home_url('/redirected page');

add_filter('registration_redirect', 'registration_redirect');


Leave a Comment

Comments (3)


4th, Feb 2015 at 9:50 am

Each and every code need to add into theme’s functions.php file?


Seb Kay (Author)

4th, Feb 2015 at 9:53 am

Yes that’s right, just copy and paste into your themes functions.php file. I’ve updated the article to explain this a bit better 🙂



18th, Dec 2017 at 12:56 am

That’s a wounderful tutorial!!! Thank you very much! I got a couple of techniques for myself! Thanks again



Inspirational Newsletter

Join the newsletter to get the best articles, tutorials and exclusive freebies every two weeks.

No spam. You can unsubscribe at any time.