WordPressテーマで編集するファイルの探し方についてよく質問を受けます。
WordPressテーマはいくつかの異なるファイルで構成されています。テーマを変更するためにどのファイルを編集すればいいのか、初心者にはわかりにくいこともあるでしょう。
この投稿では、WordPressテーマのどのファイルを編集すべきかを簡単かつ素早く見つける方法を紹介する。
WordPressテーマのテンプレートファイルを理解する
WordPressテーマはいくつかのファイルで構成されています。テンプレートファイル、カスタムのテンプレートタグや関数、テンプレートパーツ、画像、JavaScript、CSSファイルなどです。
WordPressのトップテーマはすべて、公式のベストプラクティスに従っています。これは、すべてのコードを整理するために標準的なファイルとテンプレート構造を使用していることを意味します。
例えば、WordPressテーマにはすべてarchive.php、single.php、functions.phpなどのファイルがあります。
これらのファイルはそれぞれ、WordPressサイトの特定のエリアを表示するためのテンプレートとして使用されます。例えば、single.phpは個別投稿を表示するために使用され、page.phpテンプレートは単一ページを表示するために使用されます。
WordPressのテンプレート階層を理解することで、WordPressの仕組みをより深く理解することができます。
WordPressテーマにコードを追加する必要がある場合、どのファイルを編集する必要があるかを把握するのにも役立つ。
詳しくは、初心者のためのWordPressテンプレート階層完全チートシートをご覧ください。
ということで、WordPressテーマで編集するファイルを簡単に見つける方法を見てみましょう。
WordPressテーマで編集するテンプレートファイルを探す
まず最初に、What The Fileプラグインをインストールして有効化します。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。
プラグインは箱から出してすぐに使えるし、設定することもない。
有効化した後、フロントエンドのWordPress管理バーに「What The File」メニューが表示されます。
あとはメニュー項目にマウスオーバーするだけで、このページを表示するために使用されているテンプレートファイルをリストアップしたドロップダウンメニューが表示される。
ファイル名をクリックすると、WordPress初期設定のファイルエディターが表示され、そのファイルを編集することができます。
しかし、WordPressファイルエディターを使ってテーマファイルを編集することはお勧めしません。元に戻す設定がないからです。
誤ってサイトからロックアウトしてしまった場合、FTPクライアントを使用して修正する必要があります。そのため、FTPクライアントまたはWordPressホスティングコントロールパネルのファイルマネージャーアプリを使用することをお勧めします。
テーマファイルはメモ帳のようなプレーンテキストエディターで編集できます。
WordPressのテーマに直接変更を加えるのも、良くない考えです。テーマを更新すると、その変更は消えてしまいます。
CSSを追加するだけなら、WordPressのカスタムCSSとして追加できる。それ以外のテーマファイルの変更はすべて、子テーマを作成してください。
What The Fileプラグイン」は、子テーマにコピーして編集する必要があるテーマファイルを探すのに役立ちます。
注意:このプラグインによって管理バーに追加されたメニュー項目は、ログイン中のユーザーすべてに表示され、外部サイトへのリンクを持ちます。このプラグインはステージングサイトなどの開発環境でのみ使用してください。
この投稿が、WordPressテーマで編集すべきファイルを見つけるのにお役に立てば幸いです。
WordPressテーマ開発チートシートや、WordPressで生成されたCSSクラスもご覧ください。
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.
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!
Moinuddin Waheed says
This is a bit developer oriented task but yes at times we get into the question to edit the file and get into dilemma of which one to edit to get the desired changes made.
I used to think that it is always the functions.php file that is to be changed but no the change is to be made where it is desired.
I will explore the plugin to see where we would need to make the edit and changes.
Thanks for this tutorial guide. it is really helpful understanding these concepts better.
WPBeginner Support says
You’re welcome
管理者
Jiří Vaněk says
Thank you for the tip. Sometimes, I need to make a change on a website, and one doesn’t immediately know which file to edit. This plugin can be a great helper in figuring out which template file is currently being used.
WPBeginner Support says
Glad we could share this plugin
管理者
Riyaz says
Installing this plugin made my life easier. However, some of the themes just leave something like these:
$has_sidebar = is_active_sidebar( ‘single-blog’ );
do_action( ‘mytheme_page_header’ );
and even some functions which I can find nowhere:
mytheme_get_listings_image(‘mytheme-list’)
Is there any way to find these things ?
WPBeginner Support says
You would need to manually go through the files manually, normally those would be found in the functions.php file
管理者
mark Swift says
Hi,
nice article,
but what if the files are not available in child theme which I have to edit ??
Cos says
If you copy template (.php) files to your child theme (so you can edit them and not lose your changes when the theme is updated) then what happens if the file you copied and edited is updated by the theme developer? Do you then lose the benefit of their update?
Susan Sheridan says
How about this same kind of tool for finding out which style sheets are being applied?
Bond Shands says
I had hoped to use these directions to change the Post Office Mailing Address line at the bottom of my blog. However, installing and activating the What The File plugin produced no discernible results. Nothing new appeared on my Menu Bar. Also, to be honest, your instructions left me in the dark about how I would see the plugin displayed when viewing the blog page I wished to see. (Also, I’m already a subscriber via an alternate email address).
WPBeginner Support says
Hi Bond Shands,
Each WordPress site uses a couple of templates which are loaded on each page. For example, the header and footer templates. In order to change your postal address you will need to edit the footer.php file. However, make sure that you backup your WordPress theme before making any direct changes.
Thanks
管理者