How to Add Custom PHP Code in the Astra Theme?
|
/ Documentation /Custom Code Snippets/Astra Theme & Pro Filters/ How to Add Custom PHP Code?

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 doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
On this page

Download is Just A Click Away!

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

This field is required.

REWIND

YEAR IN REVIEW

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