1

A few days ago I created a child theme of my theme zerif lite. Everything is looking good and there is no problem at all.

I just want to know are the created functions.php and style.css files correct or not. And I added some optimized files in my child theme which are already exist in parent theme (Unoptimized but same files), but i am in doubt that same files are loading 2 times from parent and child theme. I want to be sure that same files not load 2 times.

This is my style.css of child theme:

/*
Theme Name:   Zerif Lite Child
Theme URI:    http:/only4gamers.ml
Description:  Zerif Lite Child Theme
Author:       Md Umar
Author URI:   http:/only4gamers.ml
Template:     zerif-lite
Version:      1.0.0
License:      GNU General Public License v2 or later License URI:  http://www.gnu.org/licenses/gpl-2.0.html
Tags:         light, dark, two-columns,right-sidebar, responsive-layout, accessibility-ready Text Domain:  zerif-lite-child
*/

and this is function file of child theme:

<?php  
function my_theme_enqueue_styles() {  

    $parent_style = 'zerif-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' );  
?>  

I am new to wordpress and don't know much about coding. Any improvement in my style and function file is highly appreciated.

4
  • Did you mean function or functions.php?
    – Tom J Nowell
    Aug 23, 2017 at 11:04
  • i updated my post and added more details. Aug 23, 2017 at 11:22
  • Additionally to @TomJNowell's answer, I suggest you reading wordpress.stackexchange.com/questions/1567/…, this may give you more references.
    – ClemC
    Aug 23, 2017 at 11:56
  • thank you so much bro, but there is no need to make it more complicated. as i already said i am new in this coding world and don't know much about coding. this question is related to child themes. I copy above codes from here codex.wordpress.org/Child_Themes and i just simply copy and paste codes without much modification. if anyone here using child themes then he/she can easily understand my question. Aug 24, 2017 at 6:17

1 Answer 1

3

There's a simple way to test:

  • add wp_die('it works'); to functions.php, if you see it works on every page, then it's worked
  • add a silly CSS rule to style.css, e.g. body { border: 100px solid pink; }, if your pages now have a 100 pixel pink border then your stylesheet is working

If it works, then you did it correctly, if you didn't do it the correct way, it wouldn't work.

Otherwise, the only thing's I'd note are that:

  • it's functions.php not function.php
  • avoid closing PHP tags in functions.php, PHP will auto-add them if needed, and it prevents a common mistake with whitespace after the tag
  • my_theme is a very generic prefix, you should pick something more unique

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.