简体   繁体   中英

wordpress child theme functions.php

I am trying to create a Wordpress child theme and have been visiting the following website: https://codex.wordpress.org/Child_Themes .

On this website it says that I have to create two files, of which the style.css is clear, My question is about functions.php. It says at some point that I have to copy paste the following text in the newly created functions.php file:

<?php
function my_theme_enqueue_styles() {

    $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.

    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 wonder where in this php file I have to make modifications ie where do I put the name of my theme in the functionality?

Thanks,

Naveen

Add action or filter hooks can be done by functions.php

Please add wp_enqueue_scripts code in functions.php

First You need to understand how the child theme actually works. Child theme uses the files of its parent theme, and generate an another style.css for child theme. Generally, people develop a new child theme for design customization. Now if you wants to add other functionality or change the default one you will need to add it in functions.php.

Here in this code you are adding style.css file of parent theme as well as child theme.

If you still face problem there is a plugin to create child theme.

https://wordpress.org/plugins/one-click-child-theme/

Install plugin and now you just need to select the parent theme and name of your new child theme and you are good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM