Child theme customizer preview doesn't workload

admin2025-06-03  2

Quick heads up, I know nothing much about php so I might need some extra help with this. So, I have set up a while ago a child theme for Astra in Wordpress. And while everything is working well so far, I just noticed that the customizer preview page is not working, or rather not fully loading at all.

I went through the whole plugins deactivation stuff, but it didn't change anything, so when I switched to my parent theme, I noticed the customizer works. Meaning that the problem is from my child theme.

I'll put below what I have in both the style.css and functions.php files of my child theme, please do let me know if something is wrong.

/*
Theme Name: X Child Theme // Made by Y 
Author: Y 
Description: 
Template: astra
*/

Functions.php files

<?php
function astra_child_enqueue_parent_theme_style() {
// Dynamically get version number of the parent stylesheet (lets browsers re-cache your stylesheet when you update your theme)
$theme   = wp_get_theme( 'astra' );
$version = $theme->get( 'Version' );
// Load the stylesheet
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css', array(), $version );   
}
add_action( 'wp_enqueue_scripts', 'astra_child_enqueue_parent_theme_style' );
?> 

Thoughts?

Edit: My bad, I actually meant to write template there. It is declared as Templare: in the style.css file. and the comment blocks are there as well. I will edit it my post to fix it. Thanks a lot anyway

Quick heads up, I know nothing much about php so I might need some extra help with this. So, I have set up a while ago a child theme for Astra in Wordpress. And while everything is working well so far, I just noticed that the customizer preview page is not working, or rather not fully loading at all.

I went through the whole plugins deactivation stuff, but it didn't change anything, so when I switched to my parent theme, I noticed the customizer works. Meaning that the problem is from my child theme.

I'll put below what I have in both the style.css and functions.php files of my child theme, please do let me know if something is wrong.

/*
Theme Name: X Child Theme // Made by Y 
Author: Y 
Description: 
Template: astra
*/

Functions.php files

<?php
function astra_child_enqueue_parent_theme_style() {
// Dynamically get version number of the parent stylesheet (lets browsers re-cache your stylesheet when you update your theme)
$theme   = wp_get_theme( 'astra' );
$version = $theme->get( 'Version' );
// Load the stylesheet
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css', array(), $version );   
}
add_action( 'wp_enqueue_scripts', 'astra_child_enqueue_parent_theme_style' );
?> 

Thoughts?

Edit: My bad, I actually meant to write template there. It is declared as Templare: in the style.css file. and the comment blocks are there as well. I will edit it my post to fix it. Thanks a lot anyway

Share Improve this question edited Feb 18, 2019 at 15:07 Taha asked Feb 18, 2019 at 12:39 TahaTaha 11 bronze badge 2
  • What's this: add_action('wp_head', function(){? Is that really the last line of your functions file? – Jacob Peattie Commented Feb 18, 2019 at 14:34
  • Just a cookie policy that I injected in the header using wp_head! I removed the remaining part, but you can act like its not there. – Taha Commented Feb 18, 2019 at 15:06
Add a comment  | 

2 Answers 2

Reset to default 0

The issue appears to be that you're not declaring your theme as a child theme correctly. To be a child theme the theme must declare its Template: in the comment block at the top of style.css, not Child Theme Template.

Not declaring your theme as a child theme correctly means that WordPress isn't falling back to the parent theme's templates. So if you don't have an index.php file in your child theme, nothing will load.

So your child theme style.css should look like this:

/*
 Theme Name:  X Child Theme
 Description: 
 Author:      Y
 Template:    astra
*/

Also note the comment block is indicated by /* and */. They're not in your question, so I don't know if you're actually using them, but if you aren't, you need to. They're required.

I got it fixed. I am not sure how but I rewrote the functions.php file and I removed all the additional wp_head scripts and got them implemented through hooks in my theme. Teaches me not to mess too much with functions.php next time. Thanks a lot everybody

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748890603a314576.html

最新回复(0)