Back WordPress

How to Restrict a Specific Word from Post Title

WRITTEN BY ON 28 Feb 2011
7,947 VIEWS • SHARES
0 comments

This article shows simple usage of WordPress hook. The hook we are using here is post_publish, to restrict a specific word from post title. Read More: http://www.dynamicwp.net/articles-and-tutorials/how-to-restrict-a-specific-word-from-post-title/

PHP

The code should be placed in function.php

With litle modification, We can add more words. You can see the modification here: http://www.dynamicwp.net/articles-and-tutorials/how-to-restrict-a-specific-word-from-post-title

function titlerestriction($title){
	global $post;
	$title = $post->post_title;
	$restrictedWord = "forbidden";
	if (stristr( $title, $restrictedWord))
	wp_die( __('Error: This title is containing restricted word') );
}
add_action('publish_post', 'titlerestriction');

Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.