[Support request] Child theme functions.php

Home Forums Support [Support request] Child theme functions.php

Home Forums Support Child theme functions.php

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1594864
    Randy

    Hello,
    I have set up a child theme using the instructions on the GP website: https://docs.generatepress.com/article/using-child-theme/

    All is working well and I’m using several functions in the child theme’s functions.php successfully:
    add_action( ‘wp_default_scripts’
    add_filter( ‘get_canonical_url’
    add_action( ‘wp_head’
    add_filter( ‘document_title_parts’
    add_filter( ‘generate_sidebar_layout’
    add_filter( ‘generate_hook_element_display’
    add_filter( ‘the_content’
    add_action( ‘transition_post_status’
    add_filter( ‘wp_sitemaps_posts_entry’

    (I list the above in case you have any known issues with how I should use them successfully in a child theme’s functions.php…. but they seem to be working)

    The only one that does not work is from Google Tag Manager’s <noscript> tag ( instructions: https://developers.google.com/tag-manager/quickstart ):

    do_action( ‘wp_body_open’, function() {
    <!– Google Tag Manager (noscript) –>
    <noscript><iframe height=’0′ src=’https://www.googletagmanager.com/ns.html?id=GTM-xxxxxx&#8217;
    style=’display:none;visibility:hidden’ width=’0’/></noscript>
    <!– End Google Tag Manager (noscript) –>
    })

    I can get around it by adding that code as a Hook to wp_body_open using your Elements module.

    But wondering why that particular one does not work in the child functions.php? And also in general, any guidance on how do I know which functions do and don’t work when placed in the child theme’s functions.php?

    Thanks so much!
    Randy

    #1594881
    Randy

    Oops…nevermind on do_action( ‘wp_body_open’

    Rookie error: I forgot to include the ?> and <?php

    But I do still wonder about the general architecture: Any guidance on how do I know which functions do and don’t work when placed in the child theme’s functions.php?

    Also, in general, how does the child theme “point” to the parent theme since only the child theme is shown as “Active”. In other words, how do the customizations of layout, menus, etc that area set in the inactive parent them get automatically used by the active child theme?

    I know about the template directive in the style.css of the child theme… but what about everything else that is set in the parent theme since the parent them is not the active theme but its setup is still be used. I’d like to understand how that relationship gets established technically. Hope that makes sense.

    #1595211
    Leo
    Staff
    Customer Support

    Any guidance on how do I know which functions do and don’t work when placed in the child theme’s functions.php?

    There isn’t a guideline for this.

    You should only add the function you know what it’s doing so that when it’s not working, you would know.

    As for how a child theme work, maybe an article like this would help:
    https://codeable.io/what-is-a-child-theme-wordpress/

    Child themes isn’t a theme-specific feature so there should be lots of resources online that explains them.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.