Prerequisites before editing WordPress theme or plugin php files

At HanamiWEB Online School,

●Ask questions in real-time in the virtual study room!

●Ask as many questions as you want via chat!

●E-learning materials that you can learn as much as you want, 24 hours a day!

All included for just 2,500 yen/month!

If you need to customize a theme or plugin, here are some basic knowledge you should know before customizing the installed PHP.

If you edit the php files incorrectly, there is a risk that your site may break, so please proceed at your own discretion.
To ensure peace of mind, it is a good idea to always create a backup before starting work so that you can restore it at any time.

Do not edit core files directly

First of all, what is a core file?

  • Theme files
  • Plugin files

Core files are files added when installing wordrpess, such as the above. Files that are distributed by the author and have not been touched by anyone are core files. These are files that are overwritten by updates from the author.

Why shouldn't you edit core files directly?

  • If you make a mistake in even one place, it won't work.
  • The update will overwrite the modified file and the file will be restored.

So, do not edit the core files directly.

If you want to edit the theme core files

There may be times when you want to customize a theme.

  • I want to embed ad tags and analysis tags in the header
  • Edited the header/footer design
  • I want to customize the top page.

If you customize a theme, you can create a child theme and edit it there.

Nowadays, theme companies often distribute child themes for free, so it is convenient to use a distributed child theme as you do not have to create your own child theme from scratch.
&quot;xxx theme child theme&quot;<br>I&#039;m sure if you search for something like that you&#039;ll find it.

If you want to edit the plugin core file

Use the code snippet plugin.

https://wordpress.org/plugins/code-snippets/

How to Customize

Click Add New to add a new code. Simply enter the code you want to add in the Code field. You can freely enter the Title and other fields.

PHP Basics

Add Comment

Comments are useful clues for other people to use when making corrections, so it is a good idea to leave the comments intact even when adding code by copying and pasting. Add // before the start of the comment.

//Add your comment here

Start tag

The php code is

<?php

End tag

It ends with ?>. Add your PHP code between the opening and closing tags.

?>

One start and end tag per code

Do not add more than one code between one opening and one closing tag.

To safely customize:

In this way, it is better to enclose each one in start and end tags and divide them.

Bad example ①

Put php inside php

<?php
既存のコード
....
  ?>

Good example 1

You can also connect



Notes

WordPress has a rule that omits the final php closing tag. If you want to add new code to existing code, you need to add the closing tag to the existing code before adding the new custom code.

As shown in the screenshot below, the closing tag that should be on the last line, line 37, has been omitted.

About errors

We will explain some common errors.

PHP Fatal Error: Cannot redeclare function.

This error occurs when the same function is used. Try changing the function name to resolve the error.

Troubleshooting site errors

Errors can occur, so it is important to take precautions.

backup

You can easily perform backups using the upDraftPlus plugin.

You can work with peace of mind by testing the restoration from a backup in advance.

Turn on debug mode to make errors visible

You can find out where the error is by turning on debug mode.

▼How to enable WordPress debug mode (reference site)▼

https://wp.go-sign.info/how-to-enable-wordpress-debug-mode/

Stop the plugin

In some cases, the site can be restored by disabling the plugin that is causing the error. When a site breaks due to customization, you may be able to temporarily restore the site to a viewable state by disabling the plugin that is causing the error.

Leave the reskilling of your website to us!

Since 2019, we have been sharing skills related to WordPress and websites. We have accumulated case studies and know-how, and are good at quickly and accurately solving problems. If you have any concerns about your website, please feel free to contact us via our official LINE account!

↑Click to open the official LINE page

Latest Articles

(Solved) Emails sent from WordPress to Gmail are not being sent [Lollipop]
Explaining package (ticket) settings for the WordPress reservation system Amelia
Zoom Integration Server-to-Server OAuth Settings
WordPress Security Enhancement Plugin All in one WP Security ~ iframe Protection feature explained
WP Rocket - WordPress Caching Plugin
en_USEnglish