Where to Add PHP Code in Divi Theme

by | Last updated Oct 28, 2024 | Divi Tutorials

add php code in divi theme
Some of the fixes you do on your WordPress website built on Divi may require that you also add a few lines of PHP code.

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.

Shop Divi Products

Buy nicely done Divi Layouts, Child themes, and extensions for your next Divi project.

Related Articles

How to Add Padding Around Featured Images in Divi’s Blog Module

How to Add Padding Around Featured Images in Divi’s Blog Module

If you're using the Divi theme for your WordPress website and want to customize the appearance of your blog posts page, one simple tweak you can make is adding padding around the featured images. This can help create a more visually appealing layout and better...

Divi Logo Guide: Everything You Need to Know

Divi Logo Guide: Everything You Need to Know

A professionally designed logo is a powerful branding asset that can leave a lasting impression on your website visitors. Research shows that a well-designed logo can boost consumer trust in a brand by an impressive 75%. But the question most people ask is – how do...

Leave a Comment

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

WP101 - FREE WordPress Tutorials

Enter your email address below to gain access to the FREE WordPress training.

You have Successfully Subscribed!

Pin It on Pinterest