Subscribe On YouTube

Join other subscribers and enjoy other Divi video tutorials!

Where To Add Custom PHP Code Snippets In Divi

Nelson Miller Profile Orange
In this tutorial I will show you where to add custom PHP code snippets in Divi that you copy from our Divi many tutorials or other sources.

▶️ Please watch the video above to get all the exciting details! 👆

Places To Add PHP Code In Divi

In this guide, we will explore several places you can add PHP snippets in your Divi-based WordPress website. There is no right or wrong here, and no better or worse – this all depends on what is the most convenient for you and what fits best into your workflow.

A Child Theme’s Functions.php File

As a Divi user, you may have heard about something called a child theme. A child theme is an optional addition to the parent Divi theme that opens up lots of customization opportunities. We won’t go into what a child theme is here, but you can learn more about it in our guide on How To Generate A Divi Child Theme Directly On Your Site.

How To Generate A Divi Child Theme Directly On Your Site Using Divi Assistant YouTube Video Tutorial by Pee Aye Creative

Any custom PHP snippets should be placed in the Divi child theme’s functions.php file, which is the main file of any child theme. If you are copying a PHP snippet from one of our many tutorials, or from another site, you can paste it here. 

  1. Navigate in your WordPress admin area to Appearance>Theme File Editor
  2. Select your child theme from the dropdown in the top right corner.
  3. Click on the functions.php tab on the right
  4. Paste your code into the code editor area
where to add PHP code snippets in Divi in a child theme file editor

A Dedicated Code Snippet Plugin

If you are not using a child theme, or if you prefer to have each of your PHP snippets labeled and activated separately, you can check out any of the “code snippet” related plugins in the WordPress plugin repository. A new one that just released is very clever and secure called “FluentSnippets” and it has some great features, like the ability to label and activate or deactivate each snippet, conditional logic, error handling, and more. There are many others to choose from too, so it all depends on your preferences.

Any code snippet plugin will work similarly. They often have a code editor area to paste snippets for CSS, JS, and PHP. However, in the Divi theme we already have dedicated places to add code like that.

Using The Divi Assistant Plugin

If you are using our Divi Assistant plugin, then you can literally add custom PHP code snippets in the Divi Visual Builder in our custom code window! That’s right, we have invented a convenient new way to add PHP code in Divi by adding a new custom code editor window in the Divi Visual Builder with a dedicate PHP editor!

Custom PHP code must be handled carefully when working on live websites. Incorrectly formatted or written PHP code can cause errors to display, or even worse, break the site completely by causing a fatal error. However, if there is a fatal error caused by custom PHP code that you add to the PHP tab of the Divi Assistant code editor, you don’t need to worry! This is because we have created several special error handling features for this situation.

  • The PHP code will not run unless this setting is enabled. This means if there is any issue, you can always come here to simply disable this setting, and the PHP code will no longer run. This provides the opportunity to fix the error in the code without displaying an error message or breaking the site.
  • The PHP code will not run when the Visual Builder is open. This is intentionally designed to allow you to access the code editor even if there is an issue.
  • If there is any fatal error caused by PHP code in the code editor provided by Divi Assistant, it will show the error details at the bottom of the website on the frontend instead of crashing the site. You can then come here to disable the code or enable the Visual Builder, open the code editor, and edit or remove the code to fix the error.

Enabling the additional setting in Divi Assistant will activate and run the PHP code in the PHP tab in that custom code window in the Divi Visual Builder. 

Where to add PHP code snippets in Divi using the Divi Assistant plugin

Subscribe For More Things Like This!

At the start of each month, we send out a recap newsletter from the month before with family news, Divi news, our latest tutorials, and product news. Occasionally, if the news is too exciting to wait, we will send out another email separate from the monthly newsletter. That’s what you get when you subscribe, and of course you can unsubscribe if you are no longer interested!

Blog Post Optin

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy

2 Comments

  1. Joseph Haber

    will divi assistant play nicely with divi pixel?

    Reply

Submit a Comment

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

Recent Posts

0

Your Cart