How to Restrict a Specific Word from Post Title
28th Feb 2011 | Posted by reza | 8 CommentsHooks are very useful in WordPress. They allow you to “hook” custom functions to an existing function, and allow you to modify WordPress’ functionality without editing the core files.
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. You can read more about hook in WordPress here : link
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');
Put the code in your function.php. And You can replace word “forbidden” with other word you want to restrict.
- image credit -
5 Comments to “How to Restrict a Specific Word from Post Title”
Add Comments (+)-
-
Hi! Great tutorial!
I`we just opened a tutorial indexing website, http://www.tutorialswindow.com and I would like to ask you to submit some tutorials if you want…Or if you let me I could submit some of your tutorials myself using my publishing system, you would need only to register and to send me a short “About the author” text.
Thanks, you can contact me at info@tutorialswindow.com
Please email me even if you don`t like my website, because I want to know what to improve on my website!
Thanks
Csabi -
Hello,
I am working on site in wordpress, where all the Jobs are pulled from the external jobs sites, such as monster, indeed, simplyhired. jobs are getting published on site randomly. but I need to explode the jobs titles after specific ascii character ” – ” for ex Sales and Marketing Manager – Mortons Steakhouse – San Francisco, CA and extract last jobs Address from the title and call it in location column.
Can somebody give me php function for this as the ” – ” is common for all jobs titles published on site.
waiting….
Thanks
-
Hi,
Do you have a suggestion how to make this a plugin?
Trackbacks/Pingbacks
- How to Restrict a Specific Word from Post Title | The best Tutorials
- How to Restrict a Specific Word from Post Title | WebDevKungfu
- 50 Unique and Informative wordpress tutorial showcase - WordPress Vampire
Was looking for this, thanks!
I guess we can also use an array of words instead of just one, right?