Astra child theme functions php

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

1. Custom Layouts module in Astra Pro (Easiest)

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

  1. Activate the Custom Layouts 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:

  • Code Snippets
  • My Custom Functions

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 from the WordPress Dashboard > Appearance > Themes > Astra Child Theme.

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

Step 3: Navigate to the child theme’s functions.php, from the right-hand section and select functions.php.

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

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.

What Does Child Theme Mean?

A child theme is the exact replica of the parent theme that en-queues all functionalities and styles from the parent theme. The main use of the child theme is to allow customization in the theme files. Any changes you make on the theme files directly will be erased when you update the theme.

That is why we recommend using a child theme when you need to override any theme templates or add code for custom functionality. When you use the child theme, any theme customizations you make there will not be affected by the theme updates.

With Astra, you will get a ready-to-use child theme, so there is no need to create it yourself. To download and install your Child Theme, all you need to do is visit Child Theme Generator follow these steps:

Step 1 – Enter the name you wish to give your child the theme;

Step 2 – If you want to add your own branding, click on advanced options and where you can edit the Theme name, version, author, author URL, description, folder name, and screenshot;

Step 3 – Once done, click on Generate. The child theme you just generated gets downloaded on your computer as a .zip file.

Let’s Install Your Astra Child Theme Now:

Step 1 – Now that you have your child’s theme file, log in to your website Dashboard and navigate to Appearance > Themes > Add New;

Step 2 – Click on the “Upload Theme” (located on the top of the page), choose the .zip file of your child theme, and click on the “Install Now” button;

Step 3 – Activate the Child Theme. Keep in mind that though the Child Theme is the active theme, it can’t work without its parent theme – Astra. Thus, you need to have both themes (Astra theme and your Child theme) installed.

Feel free to copy any necessary Astra theme files in this child theme and customize them as you need, as not all of these will automatically be transferred to the Child Theme (for example, Additional CSS you might have added to your parent theme).

Here is a nice video made by Davinder on Learn @ BasicWP that explains the steps in detail.

Some Pro Tips:

  • If you would like to learn more about the child themes in general, check this nice article on Smashing Magazine.
  • To load unminified files of the Astra theme, use SCRIPT_DEBUG Constant.

Related Links:

  • How to add custom code to child theme’s functions.php?
  • How to edit style.css in a child theme?

How do I put codes on my Astra theme?

How to add Google Analytics code with Astra theme?.
Download Astra Hooks plugin. Install it like any other WordPress plugin and activate it..
From the WordPress dashboard navigate to Appearance > Customizer > Hooks > Header > wp_head..
Add the code with wp_head action..
Publish it..

How do you use the child theme on Astra?

How To Install Astra Child Theme?.
Step 1 – Enter the name you wish to give your child the theme;.
Step 2 – If you want to add your own branding, click on advanced options and where you can edit the Theme name, version, author, author URL, description, folder name, and screenshot;.
Step 3 – Once done, click on Generate..

How do you edit a child theme on Astra?

Through WordPress Dashboard.
Navigate to Appearance > Theme Editor..
Select Astra child theme to edit, from the upper right corner..
Select Stylesheet (style. css) to edit and paste the code at bottom of the file..
Save the changes..

What is Astra child theme generator?

The Astra Child Theme Generator lets you create a child theme with a simple click of a button. To use the generator, go to this link and fill out the form. If you click “Advanced Options,”, you can add extra details like Author, Description, and Folder Name. You can also add a screenshot if you like.

Postingan terbaru

LIHAT SEMUA