Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Adsense-Script in GRAV-Content

Started by Muut Archive 9 years ago · 7 replies · 1400 views
9 years ago

Hi

I do my first steps with the GRAV-CMS and I like it :-)

But what I can not do is to add a google-ansense script direct into the content.

Google-Search with markdown and script was not successful.

Is there any markdown "command" for a script as below?

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-xxxxxxxxxxxx"
data-ad-slot="xxxxxxxxxx"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Thanks for help and best regards

9 years ago

Hi

In the template doesn't work, because the script has to be in the middle of the content.
And an editor without script knowlege should be able to change the script in the content.

Any other ideas?

9 years ago

I think you could still add the script on your template, and then add a <span class="adsenseinsert"></span> inside markdown and then use jquery to append the ins tag inside the span.

9 years ago

oh, another idea:

  • script tags goes in template
  • create a twig file in partials/adsense.html.twig
  • include it in your markdown where you want with {% include 'partials/adsense.html.twig %}
  • check Process Twig: true in frontmatter

It should work!

9 years ago

Thanks for the answer.
Sounds very complicated..... because I am not the real coding specialist.
Maybe I try it first with a iframe.
Iframe works in Markdown.

9 years ago

Goodle doen't like adsense in iframe :-(

Any other "simple" ideas?

Thanks and best regards

9 years ago

Really, that is not hard, give it a try.
Create the file adsense.html.twig inside user/theme/yourtheme/templates/partials
This file should contain

TXT
<ins class=“adsbygoogle”
style=“display:block”
data-ad-client=“ca-pub-xxxxxxxxxxxx”
data-ad-slot=“xxxxxxxxxx”
data-ad-format=“auto”></ins>

Then, in the editor, you can keep inserting your script here at first (even if it's not really recommended), so it should look like this:

HTML
<script async src=“//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>
## this is some content

this is some paragraph with the adsense below
{% include 'partials/adsense.html.twig %}

the paragraph continue here
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

it should work!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1279 9 years ago
Archive · by Muut Archive, 9 years ago
2 886 9 years ago
Archive · by Muut Archive, 9 years ago
2 4015 9 years ago
Archive · by Muut Archive, 9 years ago
1 2891 9 years ago
Archive · by Muut Archive, 9 years ago
3 1075 9 years ago