No results found. Try again with different words?

Search must be at least 3 characters.

How to Add Custom PHP Code?

In many cases, you will need to add custom PHP code to the theme. In this article, let us explain some ways how you can do so:

1. Site Builder module in Astra Pro (Easiest)

Astra Pro Addon is a premium plugin that extends the features of the Astra theme. If you have purchased Astra Pro Addon, use the Site Builder module to add custom PHP code. Below are the steps that show how to add code –

  1. Activate the Site Builder module from Astra Pro.
  2. Insert the code in the Code Editor.
  3. Select Hooks layout and choose the appropriate action / wp_head action.
  4. Choose to display it on the Entire Website
  5. Publish the layout.

Here is an example that shows how to add Google Analytics code. Similarly, you can add any custom code.

2. With Third-Party Plugin

There are free plugins available on WordPress Repository that you can use to add custom PHP code. Below are two of them:

3. In Child Theme

You can add a filter or custom PHP code through the WordPress Dashboard, follow the steps on how you can do the same –

Step 1: Install and Activate the Astra Child Theme. If you are not sure, how to install the child theme, here is an article that will guide you through.

Step 2: Open the Theme Editor under the Appearance. Not seeing Theme Editor, troubleshoot the same.

ast-theme-editor

Step 3: Select the Astra Child theme from the drop-down and click on Select to choose it. Navigate to the child theme’s functions.php, from the right-hand section by selecting functions.php.

ast-theme-editor-child-theme

Step 4: Add your code at the bottom of the file and click on Update File at the bottom.

ast-theme-editor-child-theme-ading-custom-code

Note: If you have the Parent theme active and visit the Theme Editor, you will see the following message, which informs you about how directly editing your theme could crash your website. Click on “I understand”. 

Or if you have access to cPanel of your website, you can use FTP software like FileZilla. Below are the steps that explain how to do so –

Step 1: Install and activate the Astra Child Theme from the WordPress Dashboard.

Step 2: Open your WordPress site via FTP. We would recommend you to use FileZilla.

Step 3: Navigate to wp-content > themes > astra-child

Step 4: Right-click functions.php and select View/Edit

Step 5: Add your code at the bottom of the file and save it.

Was this article helpful?
Did not find a solution? We are here to help you succeed.

Related Docs

Astra is Free. Now & Forever.

We believe creating beautiful websites should not be expensive. That's why Astra is free for everyone. Get started for free and extend with affordable packages.

REWIND

YEAR IN REVIEW

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form
Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form