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の投稿やページに機能を追加することができる。しかし、テーマを変更したりプラグインを無効化したりすると、ショートコードは機能しなくなり、タグが読者に見えるようになります。

この投稿では、WordPressの投稿やページから未使用のショートコードを見つけて削除する方法を紹介します。

How to Find and Remove Unused Shortcodes From WordPress Posts

WordPressで未使用のショートコードは問題か?

ショートコードは、WordPress サイトに動的なコンテンツを追加する簡単な方法です。現在、多くの WordPress プラグインやテーマがショートコードの代わりにブロックを使用していますが、お問い合わせフォーム、画像ギャラリー、スライダーなどの特殊なコンテンツを追加するために、多くのプラグインやテーマがショートコードを使用しています。

例えば、シンプルなショートコードを使って美しいレスポンシブスライダーを追加できる。ページビルダープラグインやテーマの中には、ショートコードを使って個々の要素を作成するものもある。

WordPressでショートコードを追加するには、設定したキーワードを投稿タイプに入力するか、角括弧で囲んで投稿またはページに貼り付けます:

[some-random-shortcode]

しかし、プラグインを無効化したり、ショートコードが依存しているテーマから切り替えたりすると問題が発生する。そうなると、ショートコードは非アクティブになり、読者があなたのサイトにアクセスしたときに、実際のショートコードタグが角括弧で囲まれて表示されることになります。

WordPressの投稿から未使用のショートコードを見つけて削除する方法を見てみましょう。投稿やページからショートコードのタグを完全に削除する方法と、サイト訪問者から非表示にするだけの方法です。

WordPressバックエンドから未使用のショートコードを削除する

最初の方法では、サイト上の投稿日やページから未使用のショートコードを見つけて削除することで、未使用のショートコードを一掃することができます。

最初に行う必要があるのは、Shortcodes Finderプラグインをインストールして有効化することです。WordPressプラグインのインストール方法については、ステップバイステップのガイドでさらに詳しく説明しています。

未使用のショートコードを見つける

有効化した後、Tools ” Shortcodes Finderページに移動します。そこで「未使用のショートコードを探す」タブをクリックしてください。

The Shortcode Finder Plugin Allows You to Find Unused Shortcodes in Posts and Pages

初期設定では、プラグインは公開するコンテンツのみを検索します。下書きやスケジュール投稿も検索したい場合は、’Include not published contents’ ボックスをチェックしてください。

投稿’または’ページ’ボタンをクリックして、コンテンツ内で使用されていないショートコードを検索することができます。このチュートリアルでは、「投稿日」をクリックします。

プラグインが投稿を検索している間、プログレスバーが表示され、未使用のショートコードのリストが表示されます。デモサイトではこのように表示されます:

Shortcode Finder Will Display a List of Unused Shortcodes

最初の3つの検索結果は未使用のショートコードです:[some-random-shortcode][envira-gallery][custom-twitter-feeds]です。これらのショートコードが依存しているEnvira Galleryなどのプラグインは、私たちのデモサイトで無効化または削除されています。

最後の2つの検索結果は誤検出で、すべてショートコードではありません。ような特殊文字を含む投稿の結果です。そして、「simple」の結果は、「simple boat」という単語をカテゴリー:で括った投稿からのものです。

The Shortcode Finder Plugin May Include False Positives in the Search Results

自分のサイトを検索するときは、誤検出ではなく、本当に使われていないショートコードだけを削除するようにしてください。

未使用のショートコードを削除する

未使用のショートコードを投稿から削除する最も安全な方法は、ショートコードを含む各投稿またはページを手動で編集することです。これにより、誤検出をチェックし、投稿を編集する最善の方法を決定することができます。

というのも、ショートコードを削除するだけでなく、投稿内の他の資料も編集しなければならないかもしれないからです。周囲の段落は、以前ショートコードによって表示され、もう表示されていない情報を参照している可能性があります。

青いショートコードの行をクリックすると、そのショートコードを含む投稿のリストが表示されます。投稿を編集するには、「コンテンツを編集」アイコンをクリックする必要があります。

Click the Edit Content Icon to Remove the Shortcode

ヒント:各投稿を別のブラウザータブで編集する方が簡単かもしれません。各アイコンを右クリックし、メニューから「新規タブでリンクを開く」を選択するか、Ctrlキーを押しながらアイコンをクリック(Windows)するか、コマンドキーを押しながらアイコンをクリック(Mac)してください。

WordPressエディターが開いたら、投稿からショートコードを削除できます。

以下の例では、ショートコードの前の段落も削除または編集する必要があります。

You Need to Edit Each Post to Remove the Unused Shortcodes

すべての投稿から未使用のショートコードを削除し終えたら、「ページ」ボタンをクリックしてWordPressのページもクリーンアップするプロセスを繰り返してください。

WordPressフロントエンドで未使用のショートコードを非表示にする

この2つ目の方法は、過去の方法のように投稿やページから未使用のショートコードタグを削除するのではなく、サイト訪問者から非表示にするだけです。

これは、ショートコードをすべて削除する前に非表示にしたい場合に便利です。また、ショートコードを設置したプラグインやテーマを再インストールしたり再アクティブ化したりする場合に備えて、非表示にすることもできます。

まず、Remove Orphan Shortcodesプラグインをインストールし、有効化します。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。

有効化したプラグインは自動的に動作し、サイトのフロントエンドに表示されている未使用のショートコードを削除します。これにより、より良いユーザー体験を提供します。

テストサイトの例です。プラグインをインストールする前は、サイトのフロントエンドに未使用のショートコードが表示されていました。

Unused Shortcode Is Visible in Your Posts and Pages

Remove Orphan Shortcodesプラグインがインストールされ有効化された後、そのショートコードはサイト訪問者に表示されなくなります。

わざわざ探したり、何かをセットアップしたりする必要はない。箱から出してすぐに使えます。

The Remove Orphan Shortcode Plugin Hides Unused Shortcode

この投稿が、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

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

  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. Leroy says

    didn’t work as the shortcode doesn’t even show up on the draft page, but sticks to the front page on website.

    • WPBeginner Support says

      If the plugin did not find the shortcode then it likely is not in your content but could be set by your theme. We would recommend checking with the support for your specific theme and they should be able to assist.

      管理者

  3. Alex Standiford says

    I used this, but made one small change. I set the WP_Query to also look for any post type instead of just posts.


    $args = array(
    's' => $string,
    'post_type' => 'any'
    )

  4. Simon Kelly says

    What a tip! I’m moving a site from Canvas to Beaver Builder and this is just what I needed to find the Woothemes shortcodes without getting into the database. Easy. Thanks!

  5. Catherine Argyros says

    Parse error: syntax error, unexpected ‘ob_start’ (T_STRING), expecting ‘{‘ in /home2/archtyp3/public_html/wp-content/plugins/archtypesandcircles/archtypesandcircles.com-plugin.php on line 8

    I put this in my a site-specific plugin but got the above error message. please help.

    • i think ive got ti says

      i just went back in and removed all the spaces, and its WORKING! thanks again for your time and energy. I really am an absolute beginner, but with this great support Im slowly getting it… :)

  6. Nehat says

    Hello, my website is and i used before the Shortcodes Ultimate plugin, but now i don’t use that plugin and i want to remove all shortcode from that plugin leave in posts. Can you tell me for any plugin twhich can find the unused shortcode and delete automaticaly?

  7. Giochi MMO says

    There is a way to delete a specific shortcode, maintaining the text inside?

    For example: in this case [dropcap]A[/dropcap] I would like to eliminate the shortcode maintaining the “A”, or any other letter inside.

    Thanks!

  8. emeraldwave says

    It would be helpful if you could also add how to bulk replace the old shortcodes found to the new shortcodes used in the new theme, rather than just removing.

    I think most people who migrate themes will be looking to replace like me.

    Regex replace plugin is useful but does not replace shortcodes in custom post types. So we still need some kind of bulk find and replace shortcodes solution.

  9. Paul Oyler says

    Does this method still work w/ WP 4.0.1? If the shortcode we wanted to find was pb_carousel group=”x” what would be the shortcodefinder to use?

  10. Karen says

    Very helpful. But a simple Search Regex search finds the shortcode for me. That seems far less intrusive than editing the function file?

  11. Paul says

    This seems like it will be a really good idea to place in the plugin deactivation action, and not allow the user to deactivate the plugin until the shortcodes have been removed or just warn the user of which posts still have these shortcodes.

  12. raymond says

    Why not write a filter for the_content that runs a regex looking for all short codes in the post then checks their name against the array of shortcode hooks to see if it had any hooked functions and if not remove them from being displayed. Theyre still there but then readers don’t see them if you need to edit a lot of posts. You could put that same funcrionality in a plugin to list all posts with all unhooked shortcodes in one location so the user doesn’t have to know the exact shortcode name when needing to edit out unused shortcodes.

  13. omid says

    sorry i forgot to mention that we can get list all available shortcodesby global $shortcode_tags variable.

  14. omid says

    i think there might be a way.as you used the loop to find post with shortcode we can take the id of each post and with some help from wpdb class and php regex probably the goal is achivable.

返信を残す

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