Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressのタイトルに禁止ワードのリストを作成する方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

最近、あるユーザーから、WordPressの投稿タイトルに禁止ワードのリストを追加するにはどうしたらいいかという質問を受けました。

もしあなたが複数投稿者のブログを管理していて、投稿者に特定の単語やフレーズの使用を避けてもらいたいのであれば、このヒントが役に立つだろう。

この投稿では、WordPressのタイトルに禁止ワードのリストを作成する方法を紹介します。

Forbidden words list for WordPress post titles

なぜWordPressで投稿タイトルの禁句リストを作成するのか?

複数の投稿者がいるサイトで、すべての投稿者にあなたの編集スタイルや方針を伝え続けるのは簡単ではありません。WordPressのプラグインを使って編集コメントを残したり、メモを追加したり、カスタマイステータスを追加することはできますが、投稿タイトルを監視することはできません。

投稿者に公開権がある場合、不要な言葉があなたのサイトで公開される可能性があります。ユーザーから公開権を奪うことでこれを防ぐことはできますが、投稿を自分で確認して公開しなければならないため、あなたの仕事が増えることになります。

それでは、WordPressの投稿タイトルに禁止ワードのリストを簡単に追加する方法を見ていきましょう。

WordPressの投稿タイトルに禁止語リストを追加する

この方法では、WordPressサイトに手動でコードを追加する必要があります。ウェブ上のコード・スニペットをWordPressに貼り付ける方法を知っているユーザーにお勧めします。

重要:WordPressファイルにコードスニペットを追加する際は、必ずWordPressサイトをバックアップしてください。

以下のコードをテーマのfunctions.phpファイル、サイト固有のプラグイン、またはコード・スニペット・プラグインに追加するだけです。

function wpb_forbidden_title($title){
global $post;
$title = $post->post_title;
 
// Add restricted words or phrases separated by a semicolon
 
$restricted_words = "word1;word2;word3";
 
$restricted_words = explode(";", $restricted_words);
foreach($restricted_words as $restricted_word){
if (stristr( $title, $restricted_word))
wp_die( __('Error: You have used a forbidden word "'. $restricted_word .'" in post title') );
}
}
add_action('publish_post', 'wpb_forbidden_title', 10, 1);

注:禁止したい単語を$restricted_words変数に追加するのを忘れないでください。セミコロンで区切ってください。

WordPressコードスニペットプラグインのWPCodeを使用して、このコードスニペットを追加することをお勧めします。

WPCode

WPCodeは、テーマのfunctions.phpファイルを編集することなく、WordPressでカスタムコードを安全かつ簡単に追加することができます。一般的なコードスニペット、スマートコードバリデーション、条件ロジックなどのライブラリが付属しています。

まず、無料のWPCodeプラグインをインストールし、有効化する必要があります。手順については、WordPressプラグインのインストール方法をご覧ください。

プラグインを有効化したら、WordPressダッシュボードからCode Snippets ” + Add Snippetページにアクセスします。

次に、「カスタムコードを追加(新規スニペット)」設定の下にある「スニペットを使用」ボタンをクリックします。

Add a new custom code snippet in WPCode

次に、スニペットのタイトルを入力し、上記のコードを「コードプレビュー」ボックスに貼り付けます。

右側のドロップダウンメニューから、コードタイプとして「PHP Snippet」を選択することを忘れないでください。

Paste code snippet into WPCode and choose the code type

その後、スイッチを’Inactive’から’Active’に切り替え、’Save Snippet’ボタンをクリックするだけです。

Activate and save your custom code snippet

このコードでは、ユーザーが投稿を公開しようとしたときに、投稿タイトルに制限のある単語が含まれていないかチェックする関数をトリガーします。投稿タイトルに制限のある単語が見つかった場合、ユーザーに次のようなエラーを表示します:

Error shown when a user tries to publish a post with a forbidden word in title

WordPressの投稿タイトルに禁止ワードのリストを追加する方法について、この投稿がお役に立てれば幸いです。また、WordPressで投稿日にアイキャッチ画像を必須にする方法や、ドラッグ&ドロップで使えるWordPressページビルダーのエキスパートピックもご覧ください。

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

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

4件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. petri says

    Excellent, simple example. How should I modify this if I would want to make same for post content. More better if I could define post type

  3. charles langat says

    Is possible to modify the code above use it to show censored words in the wordpress posts in the text area?

  4. venkat says

    Hi ..in my wordpress site..i uploaded .sql files through ftp

    when i open that .sql file in separate page,files are forbidden…getting an error like 403 forbideen error…how can i access those files…

    pls help me out

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。