hello

 

I'm wondering how can I insert a script from Google Adsense into the <head></head> section on Backdrop CMS?

 

Is there a module that can do this?

 

Thank you very much for your answer.

Accepted answer

Hi @suriyan2538

What's your technical skill level? There's a function called backdrop_add_js() which you can add to an existing preprocess function within template.php file within your theme as the easiest way.  Or you can also create a small custom module with the script url hardcoded that will add it to the header. What you'll need is something like:

function custom_module_name_preprocess_page(&$variables) {
  backdrop_add_js('http://example.com/example.js', 'external');
}

The default behaviour is to put this in the header.

There are a couple of D7 modules that might make this easier but they haven't been ported yet.

Comments

Hi @suriyan2538

What's your technical skill level? There's a function called backdrop_add_js() which you can add to an existing preprocess function within template.php file within your theme as the easiest way.  Or you can also create a small custom module with the script url hardcoded that will add it to the header. What you'll need is something like:

function custom_module_name_preprocess_page(&$variables) {
  backdrop_add_js('http://example.com/example.js', 'external');
}

The default behaviour is to put this in the header.

There are a couple of D7 modules that might make this easier but they haven't been ported yet.

Hello @yorkshirepudding

 

First of all, I really appreciate your answer.

 

I am a newbie in this field. I have no knowledge of any themes.

 

When I was using Drupal 7 I was able to do this with the Header and Footer Scripts module.
https://www.drupal.org/project/header_and_footer_scripts

 

Thank you for your comment.

I've added a port request on your behalf to https://github.com/backdrop-ops/contrib/issues/729

If you're on github you can subscribe there but if not, I've cross referenced to this post so someone should update this post. It looks fairly straightforward, but unfortunately I don't have time to do this at present.

I've been following the project on github following your suggestions.

Unfortunately, I don't have the expertise to help with projects in Backdrop CMS because I'm weak at coding.

Thank you again

Don't worry, I wasn't expecting you to do it. I'm hoping someone will come along soon to port it; in theory I could do it, but I'm up against a deadline at the moment.