Family Encyclopedia >> Electronics

How to create a list of banned words for WordPress titles

Recently, one of our users asked us how they can add a list of banned words to WordPress post titles. If you run a multi-author blog and want authors to avoid using certain words or phrases, this tip would be helpful. In this article, we will show you how to create a banned word list for WordPress titles.

How to create a list of banned words for WordPress titles

Why create a list of banned words for post titles in WordPress?

It's not easy to keep all authors informed about your style and editorial policy on a multi-author site. You can use Edit Flow to leave editorial comments, add notes and custom statuses, but it won't control the titles of your posts.

If an author has publishing rights, unwanted words may appear on her website. You can avoid this by removing publishing privileges from users, but this means more work for you, since you will have to review and publish the posts yourself.

With that being said, let's see how you can easily add a list of banned words for WordPress post titles.

Add a list of banned words to WordPress post titles

This method requires you to manually add the code to your WordPress site. It is recommended for users who know how to paste snippets of web code into WordPress.

Important Note:Always back up your WordPress site when adding a code snippet to your WordPress files.

Simply add the following code to your theme's functions.php file or in a site-specific plugin.

 función wpb_forbidden_title ($ title) global $ post; $ title = $ post-> post_title; // Agrega palabras o frases restringidas separadas por un punto y coma $ restricted_words = "word1; word2; word3"; $ restricted_words = explode (";", $ restricted_words); foreach ($ restringido_lucas como $ restringido_principal) if (stristr ($ titulo, $ restringido_principal)) wp_die (__ ('Error: Ha usado una palabra prohibida "'. $ restringido_legua." "en el post título ')); add_action ('publish_post', 'wpb_forbidden_title', 10, 1); 

Don't forget to add the words you want to ban. $ lenguaje_Resultado variable. You need to use a semicolon to separate different words and phrases.

This code simply triggers a function when a user tries to publish a post that checks the post title for restricted words. If it finds a restricted word in the post title, it will show the user an error like this:

How to create a list of banned words for WordPress titles

That's it, we hope this article helped you learn how to add a banned word list to WordPress post titles. You can also check out our guide on how to request featured images for posts in WordPress.

If you enjoyed this article, please subscribe to our WordPress YouTube Channel video tutorials. You can also find us on Twitter and Facebook.