Jump to content

How to insert Google Adsense in pw ?


alchime.net
 Share

Recommended Posts

Hi everyone,

I'haven't found any topics about it but what would be the ways to insert the google adsense code in a page ?!?

The "body" /tinymce/ html code/ get ride of the <script type="text/javascript">

So is there an easy way to include it in the content ?

Or am i suppose to create a new field and include it in the template ?

What kind please of fields then ?

Might sound a silly question for most of you, so please don't laught at me and share some knowledges ;-)

Thanks in advance !

Alchime

-------------------------------

code given by google ads is :

<!--

<script type="text/javascript"><!--

google_ad_client = "whateverisyourcode";

/* defixxxxxxxxx */

google_ad_slot = "32xxxx920";

google_ad_width = 336;

google_ad_height = 280;

//-->

</script>

<script type="text/javascript"

src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

</script>

Link to comment
Share on other sites

For scripts of this sort, I don't think they usually belong in the site's dynamic content. I would put it directly in the template file, preferably through an include. For instance, on my sites, I keep tracking/ad scripts in a dir like this:

/site/templates/includes/google_adsense.inc

Then if a template should have the code somewhere, then my main.php or head.inc/foot.inc template might include it like this:

<?php include("./includes/google_adsense.inc"); ?>

If you want to specifically enable it on some pages and not others, then create a checkbox field, like 'toggle_adsense'. Then have your template(s) check for that:

<?php if($page->toggle_adsense) include("./includes/google_adsense.inc"); ?>
Link to comment
Share on other sites

Ryan,

As usual, Thanks for that kind of easy to follow answers :-)

It works for 90% cases of website i guess. And i definitively going to use your way of doing it..

But still, What about someone who would like to copy/past a script in the content/body part ?

I 'm wondering if it 's possible to "by pass" the way tinymce get ride of the "script brackets/code" when using the html/code.

because i'm not going to make a special template for each case !! ;-) (or am i have to ?...)

I know/guess it's a way to secure the website.. but :

I think it's the same issue for video includes from utube, FB, and so on..

I have to read other posts..

thks again

Regards !

Alchime

Link to comment
Share on other sites

Create a new textarea field and don't apply any textformatters to it. Output the contents of that textarea wherever you want to in your template file. Just be aware that you only want trusted users to be able to populate this field, as someone could just as easily populate it with a malicious <script> as with a useful one.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...