Child Theme | Tag Manager

I am new to website development. I have switched my scripts over to the tag manager and everytime I update my divi theme it deletes all my scripts. I guess that is why we add child themes. So I have a child theme up and my css modifications are added to the child theme style.css sheet and that was pretty straight forward. But I am having a harder time finding information on how to modify the child theme functions.php file. I want to add my tag manager <header> and <body> scripts into the child theme functions.php file, so I don’t keep losing my Google Analytics, Schema.org, and tag manager scripts. Like I said, I am very new to the game. Am I even saying this correctly? And if so, can someone walk me through the process of adding tag manager and other scripts to my child theme, so I can update a theme and not lose my work. I swear divi updates the dang thing daily.

  • Predrag Dubajic
    • Support

    Hey William,

    Hope you’re doing well today :slight_smile:

    Child themes don’t require any special way of editing, you can simply add your required functions there, now it depends on the scripts you want to add and where you want to add them.

    Your child theme functions.php will basically have only one function when you start and that will be the one that calls parent theme style.css file, like this:

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

    Below that code you can then add your own to include your scripts.

    You can find more info about that here:

    https://developer.wordpress.org/themes/basics/including-css-javascript/

    https://developer.wordpress.org/themes/advanced-topics/child-themes/

    https://developer.wordpress.org/reference/functions/wp_enqueue_script/

    Once you have added them that should be it, all changes made in child theme will stay there after the update and there will be no need to add them again.

    Also, when using child themes you can overwrite template files by simply moving them to child theme folder and making the changes there.

    For example, if you move header.php to your child theme that file will be used instead of the one from parent theme and then you can modify the file to your liking.

    Hope this helps :slight_smile:

    Best regards,

    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.