This article covers how to add Custom PHP & HTML to your site. There are two primary ways to add custom PHP to your site with Oxygen. The first option is to use an additional plugin to add the code; the second option is a Code Block element.
Adding Code Through a Plugin
Due to how Oxygen disables the default WordPress theme system, the custom code added to your theme's function.php file is not recognized. Instead, you'll want to create a custom plugin or use a third-party code snippet plugin to add your code. Some plugins we recommend are:
If you'd like to create a custom plugin, please see the following WordPress documentation.
Adding Code Through a Code Block
Adding custom PHP & HTML to your site using a Code Block element in Oxygen is possible. This is useful for calling functions in WordPress (we don't recommend creating functions in a Code Block), running WordPress loops, making database queries, displaying custom fields from other plugins, and other WordPress API functions.
Code added to a Code Block is executed inside Oxygen, allowing you to see the results of your code in the -Preview Window-.
Deciding The Best Method
Oxygen's Code Blocks are called during the_post WordPress action (Action Reference). So, some code will not work correctly in a Code Block and should be placed within a Plugin. Here's a quick reference showing where to add custom code to your site for common scenarios. Please note this table is simply a guide, and you'll want to evaluate which method works best for you.
Scenario | Use a Plugin | Use a Code Block |
---|---|---|
Adding new functions to your website | YES | NO |
Adding information to your site's header or footer | YES | NO |
Loading a Script or Style via HTML | YES | YES |
Running custom code on a page/template | YES | YES |
Adding a new Oxygen Condition | YES | NO |