How to hide your WordPress version number…completely

Did you know that your WordPress version number is visible to everyone?

As Matt Mullenweg rightly pointed out several years ago, simply hiding your WordPress version number is not enough by itself to stay protected from potential threats (you should always be keeping your WordPress installation up-to-date).

But perhaps you have a client who has specifically requested its removal or maybe you just like keeping things on the safe side, either way there are a lot of tutorials out there on how to remove it from various areas but none that I’ve found showing how to remove it from every area at the same time.

The WordPress version number appears in three areas:

1. Generator Meta Tag in the Header

<meta name="generator" content="WordPress 3.3.2" />

2. Generator Tag in RSS Feeds

<generator>http://wordpress.org/?v=3.3.2</generator>

3. Query Strings on Scripts & Styles

If a script or style does not specify a version number when enqueued, the current version of WordPress is used.

foo.js?ver=3.3.2

One Block of Code to Rule Them All

Just enter this into your functions.php file and your WordPress version will be safely hidden from the public.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
 
/* Hide WP version meta tag from header and generator tag from feeds
 * @return null
 * @filter the_generator
 */
function fjarrett_remove_wp_version_tag() {
	return null;
}
add_filter( 'the_generator', 'fjarrett_remove_wp_version_tag' );
 
/* Hide WP version strings from scripts and styles
 * @return {string} $src
 * @filter script_loader_src
 * @filter style_loader_src
 */
function fjarrett_remove_wp_version_strings( $src ) {
	global $wp_version;
 
	$parts = explode( '?', $src );
 
	if ( $parts[1] === 'ver=' . $wp_version ) {
		return $parts[0];
	}
	else {
		return $src;
	}
}
add_filter( 'script_loader_src', 'fjarrett_remove_wp_version_strings' );
add_filter( 'style_loader_src', 'fjarrett_remove_wp_version_strings' );
 
?>

Fork me on GitHub

However, there is one small caveat to be aware of when using this method: This function will check to see if the ver query string matches the WordPress version number, so if the version of the enqueued script happens to be the exact same as the WordPress version then its version string will be removed as well.

This will occur rarely (if ever), especially when the current WordPress version is a point release, such as 3.3.2.

I’ve been HEROized as The Solution!

Last night was a very memorable night for me as my friends at X-Team unveiled my inner superhero, dubbing me as The Solution!

The Solution

When Frankie Jarrett isn’t living his passion for working in WordPress or making music, he’s the problem solving hero known as, The Solution!

He was born with the amazing cerebral super power to solve any problem. Frankie can always figure out a way to communicate clearly with anyone. He is often there to listen and offer support to others, no matter how difficult their situation. Often Frankie only needs to say, “I’ll have to think about this problem a little”, and soon he has an exciting solution!

No situation is too big or too small and there is no danger too great for him to face. Whether you are having a tough time remembering trigonometry for your math test, or you are stranded on the roof of a burning building, The Solution can always figure out the best way to rescue someone.

Our hero also has the natural ability to inspire others, whether leading musical worship in his church or jamming with friends, Frankie uses his voice and musical talents to uplift and inspire those around him.

When not saving the innocent, Frankie spends his time watching the History channel with his wife, whom he absolutely adores.

Being HEROized is a true honor, and I am grateful to Dave and the rest of the team for recognizing me in this way.

Now to create more solutions! :)

Add first and last classes to your loop without using JavaScript

So you’re a pixel-perfect designer who wants to keep control over your WordPress loop styles? Hell yeah! You’re already pretty cool in my book.

You’ve probably got a fancy post separator, or a brilliant doodle to fit between your last post and the comments. Whatever the reason, you don’t have CSS class selectors for targeting the first or last posts in your archive – and you really need them.

There are a lot of tutorials on how to achieve this with jQuery. But it’s not worth relying on JavaScript for something that can easily be done with a little PHP magic.

First, insert this function into your functions.php file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * Display the classes for the post div and automatically mark the first and last posts
 * 
 * @param {string|array} $class - One or more classes separated by spaces
 * @param {int} $post_id - An optional post ID
 */
function fjarrett_post_class( $class = '', $post_id = null ) {
	global $wp_query;
 
	if ( $class ) {
		$class .= ' ';
	}
	if ( $wp_query->current_post === 0 ) {
		$class .= 'first';
		return post_class( $class, $post_id );
	}
	elseif ( ( $wp_query->current_post + 1 ) === $wp_query->post_count ) {
		$class .= 'last';
		return post_class( $class, $post_id );
	}
	else {
		return post_class( $class, $post_id );
	}
}

Now, open up loop.php and replace post_class() with the newly created fjarrett_post_class().

This new function accepts the same parameters as the original function, so you can use it the exact same way. The only difference will be that the first and last posts will be marked automatically with an appropriate class name. Enjoy total control. :)

If this helped you in any way I’d love to hear about it in the comments!

The simplest way to require/include wp-load.php

If you want to use WordPress functionality in a PHP file that exists outside of your WordPress installation then you need to include wp-load.php. Perhaps you could call this “hooking into WordPress”.

Maybe you’re already using some sort of relative path method, like:

<?php include '../../../wp-load.php'; ?>

But this can create problems if directories change. You need a clean, dynamic way to get wp-load.php. So here is the simplest way to do it, with just two lines of code (place it at the very top of your file):

1
2
3
4
5
6
<?php
 
$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' );
 
?>

Short and sweet :)

Disclaimer: This is intended for experimental and development purposes only. It is not advised to redundantly load WordPress on live production environments. But, why?

Joining X-Team

Not long ago I was contacted by Dave Rosen, the CEO of X-Team, who had stumbled across my blog (this one). He was looking for a WordPress guru who could help wrangle up their many projects on the technical/development side of things.

After just three days of communicating back and forth (and one Skype call) he offered me a full-time position, and I wholeheartedly accepted! He flew me to Los Angeles a few days later to sync up with his top developers, Weston and Josh, who have been temporarily living here while working at FOX Broadcasting.

Needless to say, it’s been an outstanding experience working with these two. They’re not only top notch programmers but also great guys who are a blast to hang out with and have become good friends of mine. Since I’ve been here I’ve really enjoyed soaking up all the new information and techniques X-Team uses, specifically learning to incorporate version control with Git via command line into my workflow. I’m very happy to say I’m no longer Cowboy Coding! :)

My next big task (apart from client projects) is to bring a WordPress framework into fruition for X-Team that we’re calling: WPized. Weston Ruter has laid a ton of groundwork for the WPized framework already, so I’ll be taking a lot of what he’s started and simplifying it into a tool for creating themes rapidly. I’ll also be writing a lot of documentation for our other WP developers so they will know how to use the custom helper functions the framework will offer and all of this will hopefully make the process of theming much more unified within X-Team.

It’s an extreme privilege to be doing what I love for a company that boasts some very big clients, has a long history of doing extraordinary things and has a lot of fun doing it! I am very fortunate to not only be running my own theme shop but now also working with a superb international team on WordPress projects full-time…from home!