plugins - function of parent not working in childtheme

admin2025-01-07  3

I have a plugin used on a parent theme which uses shortcode. The plugin (shortcode) works on the parent theme but when I switch to child theme it no longer works. I've only added the child theme code in the child theme function... this is the only script currently in child function.

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

I thought functions like that are inherited from parent. Any advice?

I have a plugin used on a parent theme which uses shortcode. The plugin (shortcode) works on the parent theme but when I switch to child theme it no longer works. I've only added the child theme code in the child theme function... this is the only script currently in child function.

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

I thought functions like that are inherited from parent. Any advice?

Share Improve this question asked May 3, 2016 at 1:52 lberelsonlberelson 15 bronze badges 3
  • What are the errors you are getting ? Just to know is the plugin still active after switching the theme ? – bravokeyl Commented May 3, 2016 at 5:14
  • How a plugin used on a parent theme and not on a child theme ? What do you mean ? – Sumit Commented May 3, 2016 at 5:37
  • Please use same account as you asked question with, this will allow you to comment on own questions even without reputation necessary. If you created multiple accounts by accident you can request to merge them via wordpress.stackexchange.com/contact – Rarst Commented May 9, 2016 at 19:35
Add a comment  | 

2 Answers 2

Reset to default 0

For inherited parent theme you need to add Template lines in child theme. Please read this https://codex.wordpress.org/Child_Themes

            /*
             Theme Name:   Twenty Fifteen Child
             Theme URI:    http://example.com/twenty-fifteen-child/
             Description:  Twenty Fifteen Child Theme
             Author:       John Doe
             Author URI:   http://example.com
             Template:     twentyfifteen
             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:  twenty-fifteen-child
            */

Here "Template: twentyfifteen" is important to call parent theme. Please check this in your child theme.

Also you can use this plugin to generate child theme. https://wordpress.org/plugins/one-click-child-theme/

I hope this will help you solve your problem.

If your child theme style.css contains actual CSS code (as it normally does), you will need to enqueue it as well. Setting ‘parent-style’ as a dependency will ensure that the child theme stylesheet loads after it. Including the child theme version number ensures that you can bust cache also for the child theme. The complete (recommended) example becomes:

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );

          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 ));   

           }

where parent-style is the same $handle used in the parent theme when it registers it’s stylesheet. Refer

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

最新回复(0)