And if you have never done this before, you may be wondering where exactly you will need to add the code.
Well, in this tutorial, I will show you three places where you can add PHP code.
#1. Divi Theme functions.php file
This is the most basic method to add PHP code to a theme.
For the Divi theme, the functions.php file is located at yoursite.com/wp-content/themes/Divi/functions.php.
The code can usually be placed at the end.
The major problem with this is that if the theme is updated to a new version, the functions.php file will be overwritten and changes lost.
#2. Divi Child Theme
Divi child themes were actually invented to solve the problem of losing changes whenever a theme was updated to a new version.
A child theme inherits all the functionality, code, and features of the parent theme without affecting the parent theme. This allows web developers to modify the parent theme without losing the changes when a new update is run on the parent theme.
When a PHP code is added to a Divi Child theme’s functions.php file, the code will automatically be added to the parent theme’s (Divi theme) functions.php file. That way, the code won’t be overwritten when the main theme is updated.
Pro Tip: Complete Divi Child Theme Guide For Beginners
#3. Using a Plugin
If you are the kind that doesn’t like getting his hands dirty, you may use a WordPress plugin to add a PHP code into a Divi Theme’s functions.php file.
The perfect WordPress plugin built for this purpose is called Code Snippets.
The plugin will allow you to add the code and run it within the theme without having to modify theme files or use a child theme.
When adding PHP code to a functions.php file, it is important to note that it’s best if the code is placed right before the final closing tag, or at the end of the file if there is no final closing tag.





0 Comments