solved How to use Google Adsense Code in the Tinymce html editor

derrickhand300
@derrickhand300
6 years ago
1,353 posts
Hello-
I want to add the following Adsense code into my articles just using the tinymec editor html tab
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-4020801146046639"
     data-ad-slot="9853926026"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
In the past I have added the code using
{literal} code here{/literal}
in the template editor b ut in Blog there is no template editor...
Just wondering iof there is a way to make this code work in the common tinymce html code editor?
Ive not run Google Ads in some time- Ive installed this script today in a few blogs and after several hours its still blank on the page....when I go back into the tinymce editor and check the code it looks like this
<p>
<script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</p>
<p><ins class="adsbygoogle" style="display: block; text-align: center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-4020801146046639" data-ad-slot="9853926026"></ins></p>
<p>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</p>
Thanks
updated by @derrickhand300: 05/12/18 01:34:09PM
derrickhand300
@derrickhand300
6 years ago
1,353 posts
From what I have read it seems there is a php file that needs to be edited to allow scripts in tinymce
I understand the reason for scripts being prohibited is that anyone could insert a adsense script in comment boxes etc on the site.
On my particular site i could like to ALLOW scripts in tinymce as I am the only one who has access to the editor although it seems like someone at JR could easily write a code that says "If users is admin- allows scripts- else no scripts"
Pretty strange that we cannnot ad adsense ads to our blogs because of this...just my opinion as I see blogs everywhere covered in ads...

Anyway i have been into SYSTEM CORE>.CONTRIB>TINY MCE>PLUG INS and i cannot find a file in php or anywhere in a folder called "Prohibited Elements"...this is where I have read that we can allows scripts-iframes etc....can anyone tell me where to find the file/folder for tinymce?
Thank you
michael
@michael
6 years ago
7,715 posts
script its always going to be stripped out.

It might get through if you have the ALLOW ALL HTML setting set at:
ACP -> CORE -> QUOTA CONFIG -> ALLOW ALL HTML

but allowing users to enter scripts is usually frowned upon.
derrickhand300
@derrickhand300
6 years ago
1,353 posts
michael:
script its always going to be stripped out.

It might get through if you have the ALLOW ALL HTML setting set at:
ACP -> CORE -> QUOTA CONFIG -> ALLOW ALL HTML

but allowing users to enter scripts is usually frowned upon.

Is there another way to put Google Adsense ads into my blog?
Thank you
derrickhand300
@derrickhand300
6 years ago
1,353 posts
extended_valid_elements: "script[type|defer|src|language]",
Thats in form_editor.tpl
From what i am reading using Google this is where we add or allow scripts...but looks like they are already allowed? Could this be stripping scripts even though they look to be allowed?
 paste_strip_class_attributes: true,
which is quite a bit closer than what i started with
Wonder if someone could tell me if thats what it reads...
Thanks
updated by @derrickhand300: 02/07/18 10:18:13AM
derrickhand300
@derrickhand300
6 years ago
1,353 posts
Thinking out loud
Ok Ive changed
extended_valid_elements: "script[type|defer|src|language]",
to this In SiteBuilder's Form_editor.tpl
extended_valid_elements : "script[src|type|language]",
and seem to be getting closer as less code is getting stripped.
If I can get this figured out-could the template be edited like this so that only ADMINS can add scripts?
{if jrUser_is_admin()}extended_valid_elements : "script[src|type|language]",{/if}

Seems like if this is possible it would be very useful for the websites?
Thanks

Using this adsense code and pasting into the editor
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-4020801146046639"
     data-ad-slot="9853926026"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
after saving in the editor its getting changed to this
<script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" style="display: block; text-align: center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-4020801146046639" data-ad-slot="9853926026"></ins>
<script>// <![CDATA[
(adsbygoogle = window.adsbygoogle || []).push({});
// ]]></script>
which is quite a bit closer than what I had
Sorry for so much aimless rambling on this-its just usually when i flounder around like this in public someone will come to the rescue :)
updated by @derrickhand300: 02/07/18 10:19:19AM
michael
@michael
6 years ago
7,715 posts
you cant put that code into your blogs item_detail.tpl file? that would be a better place than adding it to the blog text each time.
derrickhand300
@derrickhand300
6 years ago
1,353 posts
michael:
you cant put that code into your blogs item_detail.tpl file? that would be a better place than adding it to the blog text each time.

It goes in a different place in each blog...there is no set location
michael
@michael
6 years ago
7,715 posts
The correct way to do it would to build a module that replaced [adsense] in your editor with the actual script code when it was output.

The cheating but quicker and easier way would be to use the jrInject (" Template Inject " ) module and add:
[adsense]| <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block; text-align:center;"  data-ad-layout="in-article" data-ad-format="fluid"    data-ad-client="ca-pub-4020801146046639"      data-ad-slot="9853926026"></ins> <script>     (adsbygoogle = window.adsbygoogle || []).push({}); </script>
into it as a rule on a single line. Then in your blog post put [adsense] where you wanted it to come out.
updated by @michael: 02/07/18 12:36:39PM
derrickhand300
@derrickhand300
6 years ago
1,353 posts
Thank you-I tried it but it breaks the page- only thing that shows up is header and footer...
michael
@michael
6 years ago
7,715 posts
make sure when you enter that replacement script its all on one line! otherwise it will just be partial and that will break the page.
derrickhand300
@derrickhand300
6 years ago
1,353 posts
Thanks-ive added the code to a text editor-put it all on one line then added it to the template injection
still breaks the page
Can you tell me what this error means?
[07-Feb-2018 23:05:08 America/Tegucigalpa] PHP Notice: Undefined offset: 1 in /home/rough/public_html/modules/jrInject-release-1.0.0/include.php on line 58 [4]

I guess the template injection text box wont hold all the code on a single line...
updated by @derrickhand300: 02/07/18 09:10:34PM
michael
@michael
6 years ago
7,715 posts
Worked just fine when I tried it here.

The only issue was that when I went to edit it it didnt show [adsense] anymore, it showed the code. So on editing you'd need to put [adsense] back again.
michael
@michael
6 years ago
7,715 posts
should be adding it here:
https://www.roughneckcity.com/inject/admin/global

want me to do it for you?
SteveX
SteveX
@ultrajam
6 years ago
2,584 posts
derrickhand300:
Thanks-ive added the code to a text editor-put it all on one line then added it to the template injection
still breaks the page
Can you tell me what this error means?
[07-Feb-2018 23:05:08 America/Tegucigalpa] PHP Notice: Undefined offset: 1 in /home/rough/public_html/modules/jrInject-release-1.0.0/include.php on line 58 [4]

I guess the template injection text box wont hold all the code on a single line...

This isn't an error. It's a PHP Notice, as it says.
http://www.php.net/manual/en/errorfunc.constants.php


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
derrickhand300
@derrickhand300
6 years ago
1,353 posts
michael:
should be adding it here:
https://www.roughneckcity.com/inject/admin/global

want me to do it for you?

PLEASE Do...Ive added it there a dozen different times-each time it breaks the page where I add [ADSENSE] ...i have added the line of code to 2 different text editors-removed all spaces then copy/paste into the box at the location you linked to...same result....I KNOW its gonna work right off for you....just not for ME :)
derrickhand300
@derrickhand300
6 years ago
1,353 posts
SteveX:
derrickhand300:
Thanks-ive added the code to a text editor-put it all on one line then added it to the template injection
still breaks the page
Can you tell me what this error means?
[07-Feb-2018 23:05:08 America/Tegucigalpa] PHP Notice: Undefined offset: 1 in /home/rough/public_html/modules/jrInject-release-1.0.0/include.php on line 58 [4]

I guess the template injection text box wont hold all the code on a single line...

This isn't an error. It's a PHP Notice, as it says.
http://www.php.net/manual/en/errorfunc.constants.php

Thank you Steve!
michael
@michael
6 years ago
7,715 posts
I put [adsense] into this article at the end of it.:
https://www.roughneckcity.com/roughneck-city/oilfieldnews/1158/osha-investigates-oilfield-fatality-near-williston-north-dakota

It came out as expected.
adsense.jpg
adsense.jpg  •  721KB

derrickhand300
@derrickhand300
6 years ago
1,353 posts
michael:
I put [adsense] into this article at the end of it.:
https://www.roughneckcity.com/roughneck-city/oilfieldnews/1158/osha-investigates-oilfield-fatality-near-williston-north-dakota

It came out as expected.

Yes i also get a blank space pasting the code in the html editor- which never displayed an ad....If i paste the code in a blog vis jrblog_item_detail .tpl the add appears instantly from Google....so I dont mean to sound unappreciative...but I think the fact that its not showing means its not working
derrickhand300
@derrickhand300
6 years ago
1,353 posts
Here is what the code looks like after you use [ADSENSE]- then viewing it in the html editor
<script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" style="display: block; text-align: center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-4020801146046639" data-ad-slot="9853926026"></ins>
<script>// <![CDATA[
     (adsbygoogle = window.adsbygoogle</p>
<p><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="mce-pagebreak" data-mce-resize="false" data-mce-placeholder /></p>
<p>
<script src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js">
// ]]></script>
</p>
<p><ins class="adsbygoogle" style="display: block; text-align: center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-4020801146046639" data-ad-slot="9853926026"></ins></p>
<p>
<script>// <![CDATA[
     (adsbygoogle = window.adsbygoogle || []).push({});
// ]]></script>
</p>
derrickhand300
@derrickhand300
6 years ago
1,353 posts
No ads showing up several hours later...I removed the code. I then added the code using
{jrCore_include template="google_ads.tpl"}
to the bottom of each news article- and the ads showed up instantly..hope that helps
updated by @derrickhand300: 02/09/18 04:40:17PM
michael
@michael
6 years ago
7,715 posts
Last idea I have is to try this solution in your form_editor.tpl to try to allow direct SCRIPT through with:
https://stackoverflow.com/questions/24614301/tinymce-inserting-script-tags/24614829#24614829
script.jpg
script.jpg  •  318KB

derrickhand300
@derrickhand300
6 years ago
1,353 posts
Thanks Michael...I actually spent a day trying to make that work before posting here
I am just going to add the code in template files in predefined locations and be done with it
Thank you for your help though!

Tags