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プラグイン vs Functions.phpファイル(どちらが良いですか?)

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

WordPressプラグインをインストールすべきか、テーマのfunctions.phpファイルにコードを追加すべきか、ユーザーからよく質問を受けます。

WordPressの個別プラグインを何十個もインストールすると、サイトのパフォーマンスが低下することがあります。しかし、functions.phpファイルに直接コードを追加するのは複雑です。

この投稿では、WordPressプラグインとfunctions.phpファイルの長所と短所、そしてどちらの方法が優れているかを説明します。

WordPress plugin vs functions file

WordPressプラグインのインストールとFunctions.phpファイルのカスタムコードの比較

WordPressサイトに何かを追加するには、2つの方法があります。WordPressプラグインをインストールするか、テーマのfunctions.phpファイルにコードスニペットを追加するかです。

どちらの方法でも同じことができ、どちらも正しい。しかし多くのユーザーは、WordPressのスピードとパフォーマンスにとってどちらが優れているかを知りたがっています。

プラグインをインストールしすぎることで、サイトのスピードやWordPressのセキュリティにどのような影響が出るか心配になるユーザーもいる。また、カスタムコードを追加するとサイトが壊れてしまい、簡単に修正できないのではないかと心配する人もいます。

WordPressのパフォーマンスにとってどちらが優れているか、両方のソリューションを比較してみよう。

Functions.phpファイルの長所と短所

WordPress functions.php file

WordPressのfunctionsファイルでは、テーマ開発者がテーマのカスタム機能を定義することができます。このファイルは巨大なWordPressプラグインのように機能し、サイトに追加したい他のカスタムコードスニペットを追加するために使用することができます。

テーマのfunctions.phpファイルにカスタムコードを追加する利点は以下の通りです。

長所

  • 管理エリアのビルトインテーマエディターを使って、functions.phpファイルを簡単に編集できます。
  • すべてのコード・スニペットを1つのファイルにコピー&ペーストすることができます。
  • コードを勉強し、それがどのように機能するかを学ぶ機会を得る。

しかし、functions.phpファイルにカスタマイザーの機能をすべて保存することにはデメリットもあります。

短所

  • カスタムコードはテーマを変更すると動作しません。
  • 子テーマを使用していない限り、テーマを更新するとfunctions.phpファイルが上書きされます。
  • テーマのコードがどこで終わり、カスタマイザーのコードがどこから始まるのかを理解するのが難しくなる。
  • コード・スニペットによってはサイズが大きくなりすぎ、追加のスクリプトやスタイルが必要になる場合があります。

WordPressの関数ファイルの制限を理解する

WordPressの関数ファイルには便利なトリックがたくさんあり、とても魅力的だ。しかし、この方法でコード・スニペットを管理すると、とても面倒なことになります。

必要な機能や特徴をすべてfunctions.phpファイルに追加できるわけではありません。例えば、カスタマイザーが適切に動作するためには、追加のスクリプトやスタイルシートが必要になる場合があります。

その上、小さなエラーでサイトが壊れてしまう可能性もある。幸いなことに、もっと良い解決策がある。

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

WPCode - Best WordPress Code Snippets Plugin

WPCodeは、200万以上のサイトで使用されている最も人気のあるコードスニペットプラグインです。WordPressにPHP、JavaScript、CSS、HTMLのコードスニペットを簡単に追加することができます。すべてサイトのファイルを編集する必要がありません。

すべてのコードスニペットを1つの画面で簡単に管理でき、重要なサイトのカスタマイズを失うことなく、テーマを安全に切り替えることができます。

スマートコードスニペット検証はまた、あなたのウェブサイトを壊すことがないように、一般的なコードエラーを防ぐのに役立ちます。

ビルトインのコードライブラリには、REST APIの無効化、コメントの無効化、WordPress管理バーの無効化、SVGファイルのアップロード許可、Gutenbergの無効化など、一般的な機能リクエストに対応したスニペットも用意されています。

これにより、WordPressのパフォーマンスを低下させ、管理エリアを乱雑にする個別プラグインをいくつか置き換えることができます。

WPCode WordPress Code Snippets Library

その他の強力な機能には、プライベートクラウドスニペットライブラリ、自動コンバージョンピクセル、スケジュールスニペット、高度なeコマースロケーションとトラッキング、ダイナミックコンテンツエレメント、コードリビジョンなどがあります。

注: WPCodeの無料版もあります。

詳しくは、WordPressでカスタマイザーコードを簡単に追加する方法をご覧ください。

WordPressプラグインのインストールの長所と短所

WordPress plugins

WordPressプラグインは、WordPressサイトのアプリのようなものです。プラグインは、WordPressのコアソフトウェアにフックして、より多くの機能や特徴を提供するコードを含んでいます。

WordPressプラグインとは何か、どのように機能するのかについての投稿をご覧ください。

関数ファイルにコードを追加する代わりにWordPressプラグインを使用する利点は以下のとおりです。

長所

  • WordPressプラグインはテーマに依存しない
  • 同じコードであれば、ファンクションファイルと同じパフォーマンスへの影響がある。
  • 必要に応じて無効化、更新、再インストールすることが容易である。
  • 各プラグインの説明から何ができるかがわかるため、管理が容易

さて、WordPressのプラグインをすべてインストールすることが良いと言っているわけではない。デメリットもあります。

短所

  • 別のプラグインの更新をインストールする必要があります。
  • プラグイン投稿者は、特にそれが無料であれば、将来的にプラグインを放棄することができる
  • コードを使って練習することはないだろう
  • 複数のプラグインをインストールすると、WordPressの管理エリアが煩雑になり、パフォーマンスに影響を与える可能性があります。

しかし、WPCodeプラグインを使用することにより、これらの欠点のいくつかを回避することができます.

上記で述べたように、WPCodeは、WordPressの管理エリアを散らかしたり、パフォーマンスに影響を与えたりしないように、いくつかの個別プラグインを置き換えることができます。

WordPress プラグイン vs 関数ファイル – どっちがいいの?

WordPressに個別機能を追加したい場合で、コードを使うのが苦手な場合は、単発機能のプラグインが適しているかもしれません。

パフォーマンスに関しては、コードがどこで実行されるかは問題ではありません。functions.phpファイルから読み込もうが、区切りのプラグインとして読み込もうが、同じコードであれば、パフォーマンスに与える影響は同じです。

プラグインを選択する場合, あなたはまた、パフォーマンスを向上させる可能性のある将来の更新の恩恵を受けることができます, バグの修正, またはセキュリティ上の脆弱性にパッチを当てる.

しかし、サイトに多くの機能を追加したい場合は、WPCodeでカスタムコードを追加することをお勧めします。

一般的なサイトでは、6-8個の単発機能プラグインをインストールすることが多く、パフォーマンスに影響を与える可能性があります。その代わりに、WPCodeを使用してこれらのプラグインを置き換えることで、サイトを高速化することができます。

さらに、6-8個のプラグインを管理する代わりに、WPCodeの1つの画面でカスタマイザーコードをすべて整理することができます。これにより、サイト管理が簡素化されます。

Manage all custom snippets from one screen with WPCode

Functions.phpファイルにコードを追加するタイミングは?

WordPressテーマや子テーマに関連する機能を追加する場合、テーマのfunctions.phpファイルにコードを追加することができます。例えば、新しい画像サイズの作成、日付の表示、コンテンツの前後のカスタムコードの追加などです。

先に述べたように、WPCodeプラグインを使用してこのコードを追加することをお勧めします。テーマのfunctions.phpファイルを編集することなく、WordPressでカスタムコードを追加する最も簡単で安全な方法です。

この投稿が、WordPressプラグインとfunctions.phpファイルの違いや、どちらが優れているかを理解する一助となれば幸いです。また、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

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

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

    I see it making sense to use WPCode especially if you are not a tech savvy enough to write a custom plugin.
    Because if you would install plugin for every custom functions, each plugin has to load some basic load WordPress code like stylesheet, JS and some must load functions that will make the plugin works.
    All of these will impact on site speed.

    • WPBeginner Support says

      Not all plugins need a stylesheet or JS that is normally for plugins with complex tools or interfaces. :)

      管理者

  3. Jim Hubbard says

    What about just putting the code you would have put into functions.php into your own custom plugin. Then you can add as much code as you need (like you would in functions.php) and you only have one plugin in the admin panel. BONUS: Since you wrote it and you maintain it, there is no worry about it getting abandoned unless you no longer need it.

    • WPBeginner Support says

      It would depend on the code but if you are comfortable with creating a custom plugin, you can certainly do that.

      管理者

  4. Nate says

    So what about the extra file lookup to the plugin .php file? For example, if I take out 3 snippets from my functions.php and use 3 plugins instead, it has to go locate and pull the code from a separate file somewhere else, right? Does that not have any slight overhead?

    • WPBeginner Support says

      It should be very minor in terms of impact. As we say in the article if it is something small you can keep it in your functions.php while if it is more complicated you would want to move the code to a plugin.

      管理者

  5. Gautam subedi says

    My site’s plug-in doesn’t work, when sharing on facebook and feature photo hide and only logo appeared. Plz give me solution.

  6. Marc Queralt says

    Using separates plugins, building your own if needed, makes your WordPress easier to maintain if you keep “presentation” functionality in theme and “business” functionality in Plugins.

  7. Sallie Goetsch says

    Most of the articles I’ve read have been about whether to put your own code (or the code you’re copying from a tutorial) into functions.php or a plugin. This one seems to focus more on the question of whether to find an existing plugin or add code to functions.php. The point is well made (and I’ve made it myself) that if your code and a plugin author’s code are essentially the same, they will put exactly the same load on your site. But whether you write the code or copy the code from elsewhere, if you want it to be available to other themes, it should go into a plugin.

返信を残す

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