Jupiter child theme: how to add code to the header


#1

I made the subfolder jupiterx-child/lib/templates/structure and copied the header.php file in there but none of the scripts I added to the seem to be loaded on the website. What am I doing wrong?


#2

Not sure if it is in the documentation.
Use the following code in child functions.php to place code in the end of the head

jupiterx_add_smart_action( 'jupiterx_head_append_markup', 'link_custom_assets' );
function link_custom_assets() { ?>
    <link rel="stylesheet" href="/wp-content/themes/jupiterx-child/custom.css">
    <script src="/wp-content/themes/jupiterx-child/custom.js"></script>
<?php }

use action jupiterx_head_prepend_markup - to place code in the beginning of the head


#3

Thanks for your reply!

If I add this code in functions.php, where do I add the script? I want to add Google Tag Manager: part of the code should be in the head and the second part in the body.

Hope you can elaborate on that, thanks :slight_smile:


#4

Just use Jupiter X - Control Panel - Setting tab. It has fields for these tracking codes.


#5

That’s what I tried at first, but this only works for the Google Analytics ID. It doesn’t load the tracking codes I add in ‘Tracking Codes After Tag’ :frowning:


#6

I’m experiencing the same issue - I believe it’s a bug with the Raven plugin which controls these tracking code embeds. I’ve flagged it as a bug/ticket but haven’t had a response in days. For now, I have Raven completely disabled on most of my sites.


#7

Thanks for sharing this! However, when I turn off the Raven plugin the GTM script still isn’t loaded :frowning:


#8

I haven’t tried these inputs yet, so I don’t know if they are working. Sorry for misslead. Still you can use my suggested smart function above. Here are the examples:

jupiterx_add_smart_action( 'jupiterx_head_append_markup', 'code_in_head' );
function code_in_head() { ?>
    I AM THE HEAD CODE
<?php }

jupiterx_add_smart_action( 'jupiterx_body_append_markup', 'code_in_body' );
function code_in_body() { ?>
    I AM THE BODY CODE
<?php }

#9

I’m already glad you’re trying to help me out, thanks a lot!

If I add your code to the functions.php of the child theme, I get 4 warnings:

Warning: Use of undefined constant �jupiterx_head_append_markup� - assumed ‘�jupiterx_head_append_markup�’ (this will throw an Error in a future version of PHP) in /…/wp-content/themes/jupiterx-child/functions.php on line 62

Warning: Use of undefined constant �code_in_head� - assumed ‘�code_in_head�’ (this will throw an Error in a future version of PHP) in /…/wp-content/themes/jupiterx-child/functions.php on line 62

Warning: Use of undefined constant �jupiterx_body_append_markup� - assumed ‘�jupiterx_body_append_markup�’ (this will throw an Error in a future version of PHP) in /…/wp-content/themes/jupiterx-child/functions.php on line 67

Warning: Use of undefined constant �code_in_body� - assumed ‘�code_in_body�’ (this will throw an Error in a future version of PHP) in /…/maneros.nl/public_html/wp-content/themes/jupiterx-child/functions.php on line 67

Apparently there is a symbol missing in the code?


#10

Actually, the Tracking code inside the Jupiter X -> Control Panel -> Settings should work. However, you would need to wrap it up inside a tag. In case the issue still persists. please kindly share your WP credentials in private so I fix it for you.


#11

Hey thanks for your advice! In the meantime, Artbees support responded as well: they advised me to insert the scripts via the plugin ‘insert headers and footers’ for now and they reported the bug to their technical team. It works now, thanks!