• Resolved captainCoffee

    (@captaincoffee)


    I am having issues with removing the base Simone scripts and styles and re-enqueueing the ones from the child theme. I need to change the font stack and many of the media queries and would rather not do that directly in Simone. My child theme is “ip” and the functions.php code is below.

    If anyone has some insight as to what I did wrong, or could post an example of how it should be done, I would appreciate it. Thanks.

    <?php
    
     add_action( 'wp_enqueue_scripts', 'dequeue_parent_theme_styles', 11 );
     function dequeue_parent_theme_styles() {
       wp_dequeue_style( 'simone-parent-style' );
       wp_dequeue_style( 'simone-layout' );
       wp_dequeue_style( 'simone-google-fonts', );
       wp_dequeue_script( 'simone-superfish-settings', );
       wp_dequeue_script( 'simone-masonry', );
     }
    
     /**
     * Enqueue scripts and styles.
     */
    function ip_scripts() {
       wp_enqueue_style( 'ip-style', get_stylesheet_uri() );
       wp_enqueue_style( 'ip-style-custom', get_template_directory_uri() . '/style-custom.css', array( 'ip-style' ) );
       wp_enqueue_style( 'ip-layout' , get_template_directory_uri() . '/layouts/content-sidebar.css' );
       wp_enqueue_script( 'ip-superfish-settings', get_template_directory_uri() . '/js/superfish-settings.js', array('jquery'), '20140328', true );
       wp_enqueue_script( 'ip-masonry', get_template_directory_uri() . '/js/masonry-settings.js', array('masonry'), '20140401', true );
    
    // Open Sans + Open Sans Condensed
       wp_enqueue_style( 'ip-google-fonts', '//fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic|Open+Sans+Condensed:700' );
    
    add_action( 'wp_enqueue_scripts', 'ip_scripts' );
Viewing 9 replies - 1 through 9 (of 9 total)
  • dunno if it helps or it is strictly related to your problem, but this post solved my/our issue on enqueuing styles
    https://mor10.com/challenges-new-method-inheriting-parent-styles-wordpress-child-themes/

    hope it helps, let me know
    G.

    Thread Starter captainCoffee

    (@captaincoffee)

    Thanks for the help. I need to change many of the items and will have to spend the time walking thru them. Thanks again.

    Far from being a php expert, but is it really necessary to dequeue all that stuff in your original snippet?

    I used the snippet in that article and I’ve been able to enqueue js and custom-child theme style.css

    about google fonts, why don’t you try this in your functions.php?

    // Adding a Google Fonts
    add_action( 'wp_enqueue_scripts', 'my_google_font' );
    function my_google_font() {
    	wp_enqueue_style( $handle = 'my-google-font', $src = 'https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic', $deps = array(), $ver = null, $media = null );
    }

    use it with whatever font you need, even multiple fonts.

    @giorgio

    How did Morten’s article solve your problems about enqueueing? I’d love to know. It seems to have opened a giant can of worms for me. Now I’m finding lots of articles with others feeling similarly.

    I don’t know php and am trying to use Simone. I’m experiencing all sorts of problems with the child theme because I just followed the Codex example for enqueueing (at least in part, because it completely ignores the extra layout stylesheets). How would you enqueue Simone’s stylesheets and a child style sheet (or two or three)?

    Some issues I’m experiencing:

    • Adding header.php file to my theme breaks it,
    • Having similar problems with adding a child theme footer.php file,
    • Child theme customizer does not include the option of switching sidebar from right to left,
    • Social Menu isn’t available in Child theme admin unless I add function to my child theme function.php file – and then it doesn’t show in the navbar on my page even though I’ve created a “Social Menu” and populated it on the menu page. Since I can’t get the child theme to accept a header.php file, I assume that is a source of the problem – which probably leads back to how I’ve enqueued things

    The parent theme is exemplary in its coding – and we’ve even got the Lynda.com tutorials to walk us through it, but I’m concerned I may have to abandon it if I can’t get a child theme going correctly…

    If anyone has enqueued this theme successfully, please post your method or direct me to where it may already be posted. Gracias.

    Here’s what I did:

    /*Enqueue the parent style sheet and then the child style sheet*/
    
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
        wp_enqueue_style( 'simone', get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'pdxsa-child',
            get_stylesheet_directory_uri() . '/style.css',
            array('simone')
        );
    }

    @danwpc
    after Morten opened the Pandora box we all tried similar solution to the one originally suggested by him.

    With the latest version of Simone you don’t need anymore to enqueue the style.css for the child-theme, Simone does that for you!

    If you check in the Simone’s functions.php there is this code:

    // Load parent theme stylesheet even when child theme is active
               if ( is_child_theme() ) {
                      wp_enqueue_style( 'simone-parent-style', trailingslashit( get_template_directory_uri() ) . 'style.css' );
              } else {
                      wp_enqueue_style( 'simone-style', get_stylesheet_uri() );

    This actually the built-in solution to you question.
    I hope it helps, I use Simone extensively and I only use it with child-themes without adding anything.

    On another line the code you are using it is bit different by the the one I would use, try this one:

    //Inheriting parent styles in WordPress child themes
    add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);
    
    function enqueue_child_theme_styles() {
        wp_enqueue_style( 'child-style', get_stylesheet_uri(), array('simone-style') );
    }

    let me know ??

    Giorgio, grazie assai! Non ho visto questo in nessun documentation. I’ll go back and check. I love this theme – because I can depend on the coding.

    This directly from Morten in an email this morning:

    The answer to your question is in this article.

    Basically any child theme of Simone now automatically inherits the parent theme stylesheets in the right order. All you have to do is create your style.css file in the child theme and it automatically kicks in. The article linked above also provides an explanation of how to dequeue the parent theme stylesheets if you want to get rid of them.

    Great I missed that article!
    https://mor10.com/simone-2-0-custom-backgrounds-sidebar-position-rtl-support/
    Thanks for sharing this:

    To deactivate the parent theme stylesheets all together or individually you can do so by adding wp_dequeue_style() functions in the child theme functions.php file as in this example:

    <?php
     add_action( 'wp_enqueue_scripts', 'dequeue_parent_theme_styles', 11 );
     function dequeue_parent_theme_styles() {
       wp_dequeue_style( 'simone-parent-style' );
       wp_dequeue_style( 'simone-layout' );
     }

    Glad to see this resolved. I’m closing the ticket. Let me know if you need it reopened.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘child theme and enqueue-ing new scripts and styles’ is closed to new replies.