Auto change incorrect WordPress spellings

WordPress noobs might be unfamiliar with the correct and proper spelling of WordPress, which is capital W and a capital P, all one word.

So how about adding a function into your theme that will auto correct any misspellings?

And now, the simple (redundant code)

function thefrosty_spell_wordpress_correct($text) {
	$text = str_replace('Wordpress', 'WordPress', $text);
	$text = str_replace('wordpress', 'WordPress', $text);
	$text = str_replace('wordPress', 'WordPress', $text);
	$text = str_replace('word-press', 'WordPress', $text);
	$text = str_replace('wOrdpRess', 'WordPress', $text);
	$text = str_replace('wp', 'WordPress', $text);
	$text = str_replace('WP', 'WordPress', $text);

	return $text;
}

As you can see, we’re just copying multiple code, and trying to find all the matches in which one might write WordPress incorrectly.

So now, the more advances replacement

I’ve added to the function, so that it won’t replace wp inside of an image.

function thefrosty_spell_wordpress_correct($text) {
	$ignore = '/([^]+)]+>|]+>([^]+)/'; //image pattern

	if ( preg_match_all($ignore,$text,$replace,PREG_PATTERN_ORDER|PREG_OFFSET_CAPTURE) ) {
		return $text;
	}
        else {

	$pattern[] = '/bword[- ]?pressb/i';
	$pattern[] = '/bWPb/i';

	$replace = 'WordPress';

        //removed "foreach" as suggested by @utkarshkukreti here
	$text = preg_replace( $pattern, $replace, $text );

	return $text;
        }
}

This code is using regular expression, and an array of patterns. The first is looking for words matching wordpress or word-press with case insensitive matches.
While the second is looking for case insensitive matches to WP.

Pretty simple so far

Now we need to add either of the above code to your theme’s function.php file, then add the necessary filter! To do so just add this line:

add_filter( 'the_content', 'thefrosty_spell_wordpress_correct', 10, 1 );

Now, if you’d like, you can also replace incorrect spellings in other area’s of WordPress. For example just add in any of the following filters you’d like.

add_filter( 'comment_text', 'thefrosty_spell_wordpress_correct', 10, 1 );
add_filter( 'the_title', 'thefrosty_spell_wordpress_correct', 10, 1 );

Just to name a few

That’s it!

Now I’d also like to mention you can create this as a plugin, or even download the multiple plugins that are already out there that do this very thing.

  1. WordPress Auto Correct
  2. Ozh’ Correctly Spell WordPress
  3. It’s WordPress

If you’re interested in adding this function as a plugin, just use the code below..

/**
 * Plugin Name: Spell WordPress Correctly
 * Plugin URI: http://wp.me/p4gJ2a-rm
 * Description: Writes WordPress as it should be written.
 * Version: 0.2
 * Author: Austin Passy
 * Author URI: http://austin.passy.co/
 */

function thefrosty_spell_wordpress_correct($text) {
	/** advanced *don't match the following **/
	$ignore = '/([^]+)]+>|]+>([^]+)/'; //image pattern

	if ( preg_match_all($ignore,$text,$replace,PREG_PATTERN_ORDER|PREG_OFFSET_CAPTURE) ) {
		return $text;
	} else {

	$pattern[] = '/bword[- ]?pressb/i';
	$pattern[] = '/bWPb/i';

	$replace = 'WordPress';

	//foreach ( $pattern as $patterns )
		$text = preg_replace($pattern,$replace, $text);

	return $text;
	}
}
add_filter( 'the_content', 'thefrosty_spell_wordpress_correct', 10, 1 );