$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>functions - How do I create a child theme from PowerMag theme|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

functions - How do I create a child theme from PowerMag theme

matteradmin7PV0评论

I am using PowerMag 2.5 as parent and can't seem to find a way to get a working child theme. As far as I am now, I can only extend css in the style.css but as far as overriding, nothing has worked. When I copy over e.g. the header.php from parent to child and make some edits to the code it does not work. The very big functions.php from the parent theme is overwhelming me and I do not know how to get it working.

child > style.css

/*
Theme Name:   PowerMag Child
Theme URI:    
Description:  PowerMag Child Theme
Author:       djwd
Author URI:   
Template:     powermag
Version:      1.0.0
License:      GNU General Public License v2 or later
License URI:  .0.html
Tags:         dark,light,three-columns,two-columns,left-sidebar,right-sidebar,featured-image-header,featured-images,full-width-template,rtl-language-support,sticky-post,theme-options,threaded-comments,translation-ready,post-formats,custom-menu,custom-background,flexible-width
Text Domain:  powermag-child
*/

child > functions.php

<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}

parent > functions.php

The file is to big for posting so I uploaded it here

I am using PowerMag 2.5 as parent and can't seem to find a way to get a working child theme. As far as I am now, I can only extend css in the style.css but as far as overriding, nothing has worked. When I copy over e.g. the header.php from parent to child and make some edits to the code it does not work. The very big functions.php from the parent theme is overwhelming me and I do not know how to get it working.

child > style.css

/*
Theme Name:   PowerMag Child
Theme URI:    https://themeforest/item/powermag-the-most-muscular-magazinereviews-theme/4740939
Description:  PowerMag Child Theme
Author:       djwd
Author URI:   http://themeforest/user/djwd
Template:     powermag
Version:      1.0.0
License:      GNU General Public License v2 or later
License URI:  http://www.gnu/licenses/gpl-2.0.html
Tags:         dark,light,three-columns,two-columns,left-sidebar,right-sidebar,featured-image-header,featured-images,full-width-template,rtl-language-support,sticky-post,theme-options,threaded-comments,translation-ready,post-formats,custom-menu,custom-background,flexible-width
Text Domain:  powermag-child
*/

child > functions.php

<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}

parent > functions.php

The file is to big for posting so I uploaded it here

Share Improve this question asked Nov 19, 2018 at 21:07 Empire HiveEmpire Hive 1 3
  • Not sure what your asking about the parent functions.php You don't need to do anything with the parent functions.php for your child theme. You should only start with the child style.css and child functions.php. That's all you need to start a child theme. Once you have that (which you have), you can add custom versions of parent files, but you do nothing with the parent functions.php - leave that one alone. – butlerblog Commented Nov 20, 2018 at 1:31
  • @butlerblog I only added the parent functions.php to show how styles are enqueued. Because when I create a basic child theme, I can't override any css. – Empire Hive Commented Nov 20, 2018 at 8:15
  • Ahhh... got it. I took a look and I do have some ideas. Not sure if they will help (hopefully they will!). It's too long for a comment so I posted as an answer below. – butlerblog Commented Nov 20, 2018 at 12:53
Add a comment  | 

3 Answers 3

Reset to default 0

Just create a folder named PowerMag-child

  • Put style.css with below text

    /*
    Theme Name:   PowerMag Child
    Theme URI:    https://themeforest/item/powermag-the-most-muscular- magazinereviews-theme/4740939
    Description:  PowerMag Child Theme
    Author:       djwd
    Author URI:   http://themeforest/user/djwd
    Template:     powermag
    Version:      1.0.0
    License:      GNU General Public License v2 or later
    License URI:  http://www.gnu/licenses/gpl-2.0.html
    Text Domain:  powermag-child
    */
    
  • functions.php with below code and nothing else

    <?php
    

Based on your description and then the additional mention in the comments, I would suspect that the issue is the load order of the various stylesheets involved. I'd suggest taking a look at the header via "view source" in your browser to see what order the stylesheets are in when everything is loaded.

Check load order and adjust enqueueing priority

Stylesheets that load later will override styles from an earlier stylesheet. So if you have stylesheets from the parent that are loading after the child theme's styles.css, those later stylesheet properties will be what is applied.

Normally, the child stylesheet should load after any enqueued styles from the functions.php of the child and the parent. But if that doesn't happen, you may need to make adjustments accordingly.

One thing you could do is add a stylesheet in your child theme folder to contain your override styles (separate from your child theme stlyesheet), then load that with wp_enqueue_style(). Hook it to the wp_enqueue_scripts action and set the priority to be later (like 99 or 100). Reviewing your parent functions.php indicates that the enqueued styles are enqueued at the default priority, which is 10, so setting this later priority should load your custom stylehseet later than the enqueued styles from the parent.

It may take some jiggering around, but reviewing what loads and when in the "view source" in your browser should help you get things coming in the right order.

What if everything is in the right order and I still can't override?

Make sure that the styles your trying to override are actually in the stylesheets you think they are in. Use the browser inspector to view the style and it should tell you what the source stylesheet is for that style.

Also, using the browser inspector should tell you if the developer used the !important CSS specification. I personally hate when they do this - it's a bad practice usually done out of laziness because they can't figure out the correct way to apply a property. The problem with it is that simply defining a new property then gets ignored. In that case, you need to have a later load of your CSS coupled with also specifying !important to override the first one. You may also need to set the particular property to initial to completely reset it.

Hope this helps you track down the problem.

Please replace your code with this code in child functions.php file. i think some priority OR dependence problem. For More info

<?php
function my_theme_enqueue_styles() {

    $parent_style = 'parent-style';

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
Post a comment

comment list (0)

  1. No comments so far