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

WordPressで未使用のショートコードを検索して削除する方法

私たちは数え切れないほどのWordPressサイトを手がけ、未使用のショートコードが徐々に蓄積されていくのを目の当たりにしてきました。

これらの忘れ去られたショートコードは、データベースのスペースを占有するだけでなく、実際にサイトの速度を低下させ、潜在的なセキュリティの脆弱性を生み出す可能性があります。さらに悪いことに、ページ上に醜い壊れたコードスニペットとして表示されることもあり、あなたのサイトをプロらしくないものにしてしまいます。

良いニュースは、これらの未使用のショートコードを見つけて削除することは、見た目ほど複雑ではないということです。

このステップバイステップのガイドでは、これらの厄介なショートコードを特定し、WordPress サイトから安全に削除する方法を具体的に紹介します。このチュートリアルを読み終える頃には、数個の迷子のショートコードであろうと、数十個のショートコードであろうと、よりクリーンで高速なサイトになっていることでしょう。

How to Find and Remove Unused Shortcodes From WordPress Posts

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

ショートコードを使用すると、WordPress サイトに動的なコンテンツを簡単に追加できます。現在、多くのプラグインやテーマがブロックを使用していますが、ショートコードは、以下のような特殊な要素を追加するために今でも広く使用されています:

  • お問い合わせフォーム– 投稿やページ内にシームレスにフォームを埋め込むことができます。
  • Imageギャラリー– 視覚的にアピールする写真コレクションを表示します。
  • スライダー– 画像、動画、またはその両方のための美しくレスポンシブなスライダーを追加します。
  • ページビルダー要素– カスタムのセクションやレイアウトを作成できます。

一般的に、WordPressでショートコードを追加するには、設定したキーワードを投稿タイプまたはページに角括弧で囲んで貼り付けます。こんな感じだ:

[some-random-shortcode]

WordPressでショートコードを追加する方法については、初心者向けガイドをご覧ください。

さて、プラグインを無効化したり、ショートコードが依存しているテーマから切り替えたりすると問題が発生する。

そうなると、ショートコードは非アクティブになり、読者があなたのサイトにアクセスすると、実際のショートコードタグが角括弧で囲まれて表示されます。😓

以下のカテゴリーでは、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]です。

ここから、これらのショートコードが依存しているプラグインがデモサイトで無効化または削除されていることがわかります。例えば、未使用のショートコードの 1 つは、Envira Galleryプラグインから来ています。

最後の2つの検索結果は誤検出で、すべてショートコードではないことに注意してください。

というような特殊文字が羅列された投稿の結果である。一方、’simple’の結果は、’simple boat’とカテゴリー:Square括弧でくくった投稿によるものである。

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

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

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

未使用のショートコードを投稿から削除する最も安全な方法は、ショートコードを含む各投稿またはページを手動で編集することです。

これにより、誤検出をチェックし、投稿を編集する最善の方法を決定することができます。

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

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

Click the Edit Content Icon to Remove the Shortcode

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

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

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

You Need to Edit Each Post to Remove the Unused Shortcodes

投稿から未使用のショートコードを削除したら、次はページを整理しましょう。ページ」ボタンをクリックし、このプロセスを繰り返します。

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サイトでは、コンテンツの検索や置換が必要になることが多々あります。例えば、サイトのドメイン名を変更したり、HTTPSに切り替えたりすると、URLの更新が必要になります。また、古い情報やタイプミス、壊れたショートコードを修正するのにも便利です。

リブランディングや、頻繁に使用する画像を置き換える必要がある場合、検索と置換を使えば、すべてを簡単に素早く更新できます。これにより、時間を節約し、サイト全体で一貫したコンテンツを維持することができます。

WPCodeチームによって作られたSearch & Replace Everythingは、WordPressのコンテンツを検索・置換するための最高のツールです。テキスト、画像、そして特定のデータベースコンテンツにも使用できます。

Backup warning

しかし、作業を始める前に、問題を避けるためにWordPressサイトをバックアップしてください。

詳しくは、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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

アバター

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.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

23件のコメントLeave a Reply

  1. Leroy

    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

      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.

      Admin

  2. John E

    Thanks for this article. It helped me fix a big problem and save a bunch of time!

  3. Alex Standiford

    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

    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

    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

      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

    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. yuvaraj

    is anyways to find it on pages in-spite of posts

  8. Giochi MMO

    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!

  9. emeraldwave

    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.

  10. Paul Oyler

    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?

  11. Bill

    If the plugin is reactivated, should the shortcodes become functional again?

  12. Karen

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

  13. Paul

    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.

  14. raymond

    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.

  15. omid

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

  16. omid

    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.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.