find コマンドを使う
Linaxにはファイルを検索するコマンドがあります。それを使って目的のファイル・ディレクトリを探します。 使い方は下のような感じです。sudo find / -name 検索したいファイル名またはディレクトリ名
そして、Wordpressのファイルが置いてあるディレクトリはwp-contentです。したがって、wp-contentを探すために以下のコマンドを実行します。
sudo find / -name wp-content
そしたら、このディレクトリの場所が/var/www/html/wp-contentとわかるので、cd(ディレクトリを移動するコマンド)でそこへ飛びましょう。(/var/www/html/は人によって違うかもしれませんがfindで調べたディレクトリの場所をコピペしましょう。)
cd /var/www/html/wp-content
移動できたら、ls(現在いるディレクトリのファイルを表示させるコマンド)を実行しましょう。
[email protected]:/var/www/html/wp-content$ ls
cache index.php languages plugins themes updraft upgrade uploads
このように表示されると思います。テーマのPHPなどはthemesに入っているので、またも、cdコマンドで移動して、ファイルを見てみましょう。
[email protected]:/var/www/html/wp-content$ cd themes/
[email protected] vm:/var/www/html/wp-content/themes$ ls
index.php luxech luxeritas twentyseventeen write
私はluxeritasという、テーマを使っているので、このように表示されます。多くの人は子テーマでPHPを編集していると思います。わたしも子テーマを編集していてアクセスできなくなったので、luxechに移動して子テーマのPHPを編集します。おそらくluxechはluxeritas childの訳だと思います。
それでは、移動します。
[email protected]:/var/www/html/wp-content/themes$ cd luxech/
[email protected]:/var/www/html/wp-content/themes/luxech$ ls
add-amp-body.php editor-style.min.css luxech.js style-amp.css
add-analytics-head.php fonts luxech.min.js style.css
add-analytics.php functions.php phrases style.min.css
add-footer.php htaccess_en.txt readme_en.txt style.replace.min.css
add-header.php htaccess.txt readme.txt webfonts
design images screenshot.jpg
editor-style.css license.txt shortcodes
問題のPHPファイルはfunctions.phpなので、それを編集します。
[email protected]:/var/www/html/wp-content/themes/luxech$ sudo vim functions.php
vimの使い方がわからない場合は調べてて、編集してください。これで、追記したところを消去したら、再びアクセスできるようになります。
ちなみに、編集していたファイルの場所はこのように表示されています。この画面を閉じていない場合はコピペで目的のファイルまでたどり着けます。
