Cyber Week Sale! Get $20 off GP Premium, $40 off our new Lifetime license, and 45% off license renewals/extensions! Learn more

[Resolved] Enqueuing to create child themes with GP Premium

Home Forums Support Enqueuing to create child themes with GP Premium

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #159743
    NBC

    The WordPress Codex officially deprecates the longstanding method of using child themes by importing the parent themes CSS.

    But when I read the discussion linked above, it clearly states the following:

    The correct method of enqueuing the parent theme stylesheet is to add a wp_enqueue_scripts action and use wp_enqueue_style() in your child theme’s functions.php. You will therefore need to create a functions.php in your child theme directory. The first line of your child theme’s functions.php will be an opening PHP tag (<?php), after which you can enqueue your parent and child theme stylesheets. The following example function will only work if your Parent Theme uses only one main style.css to hold all of the css. If your theme has more than one .css file (eg. ie.css, style.css, main.css) then you will have to make sure to maintain all of the Parent Theme dependencies.

    I said “clearly states,” but the only thing that’s clear about this is that it sets up the objective without ever explaining how to accomplish it. Because GP, and therefore GP Premium, uses multiple CSS files, how on earth do I go about creating a child theme using the currently recommended method?

    #159807
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    GP actually does this for you, so you just need to create a child theme style.css file with the appropriate headings, and GP does the rest.

    Here’s the snippet from GP:

    if ( is_child_theme() ) :
    	wp_enqueue_style( 'generate-child', get_stylesheet_uri(), true, filemtime( get_stylesheet_directory() . '/style.css' ), 'all' );
    endif;

    It checks if a child theme is activated, and if it is, it enqueues the style.css file found in the child theme main directory.

    Let me know if you need more info 🙂

    #159830
    NBC

    Except that none of my custom typography appears, except for the typeface selected in the header. The body copy shows up in a generic sans serif typeface, not the slab serif I chose for it.

    I was assuming this stemmed from a failure to load whichever CSS file records the Typography selections in the Customizer, and that I needed to pursue the enqueuing method to assure that the rest of the CSS files loaded in.

    I can’t show you a screenshot because I’m working locally under MAMP.

    BTW, thanks as always for all you do to make this such an awesome theme!

    #159834
    Tom
    Lead Developer
    Lead Developer

    So when you choose a font in “Customize > Typography”, it’s not applying to the site?

    Can you try #1 on this page?: https://generatepress.com/knowledgebase/debugging/

    #159841
    NBC

    I’m not using any non-GP plug-ins, so that debugging step doesn’t apply.

    It was working before I enabled the child theme.

    Here’s the entirety of the child theme’s style.css file content. The other two files in the child come from your basic child package, including a theme screenshot PNG and a functions.php file.

    /*
     Theme Name:   GeneratePress child
     Theme URI:    http://generatepress.com
     Description:  GeneratePress child theme
     Author:       Thomas Usborne
     Author URI:   http://edge22.com
     Template:     generatepress
     Version:      0.1
     Tags: two-columns, three-columns, one-column, right-sidebar, left-sidebar, fluid-layout, responsive-layout, custom-header, custom-background, custom-menu, custom-colors, sticky-post, threaded-comments, translation-ready, featured-images, theme-options, light, white, dark, black, blue, brown, gray, green, orange, pink, purple, red, silver, tan, yellow
    */
    @import url("../generatepress/style.css");
    
    .highlight-text { background-color:#FFFF00; }
    #159876
    Tom
    Lead Developer
    Lead Developer

    Ah, get rid of this line:

    @import url("../generatepress/style.css");

    That should do it 🙂

    #159930
    NBC

    #brainfail
    Urgh, thanks for rescuing me. I wish I could just edit the files in the child without having to deactivate it, delete it, and reupload it. <sigh> (slow computer)

    So now that I’ve revealed myself as the utter idiot I am, how about another question that’s apt to confirm the same classification? 😉

    Is there any way to create custom styles in a child theme and reveal them in the Customizer so as to use typefaces other than the basics? As far as I can tell, the coding and syntax required for that task reaches far beyond the basics into astrophysical territory. IOW, way beyond my meager paygrade.

    #159971
    Tom
    Lead Developer
    Lead Developer

    A lot of places still say to add that @import line – totally not your fault 🙂

    For the child theme question, it’s possible, but you’ll have to use some PHP.

    More info here: https://generatepress.com/forums/topic/how-can-i-create-a-child-theme-that-comprehends-customizer-settings/#post-114781

    #160030
    NBC

    Thanks, Tom! I appreciate your help!

    #160069
    Tom
    Lead Developer
    Lead Developer
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.