Adding AdSense Code Into A WordPress Theme

Adding or embedding AdSense ads or any type of script or code into a is pretty easy once you understand where to place it. In order to do that you first need to know what some of the code in your means. This WordPress guide will show you what some of the themes code means and where you can embed scripts like AdSense, HTML code or even images.

In order to edit your theme from within the your themes files must writable. Do do that you need to change the permissions, or CHMOD of the themes files to at least 666 or 777. You could also work on them in the hosting accounts file manager or on your computer and FTP upload the changes files. I prefer to edit the theme from the dashboard.

Before you get started you should copy any file you are attempting to edit and save it in a text file on your computer. If anything goes wrong you can simply paste the unedited version back to undo any damage. You have been warned!

Starting from the top of the WordPress blogs main page, just above the post you can place your AdSense script like shown on this blog, a graphic, banner ad, both AdSense and a banner like shown on my other Work At Home Business Blog, or anything else for that matter. Keep in mind that Google will usually only show three AdSense blocks per page, so if you place AdSense into your WordPress theme and also in your posts and then in the sidebar, usually only the top three blocks will show. The remainder will be open space.

The place to add your code is in the main index template (index.php) and if desired can also be placed in the single post (single.php), page template (page.php), archives and if your theme has one the 404 template. Open one of the files and place your code just above the content which is code that looks like this:

Your Code Here

<?php if (have_posts()) : //Are there any posts? ?>

Other places to place the code are:

Below the post above or below the comments would be:

<?php if ( comments_open() ) : //if comments are allowed ?>

You can experiment with many different places, just be sure to backup any file you are attempting to edit, and that the AdSense code or banner fits in the area and that all HTML or script tags are properly closed. It would also be wise to view your changes in different browsers and different size windows to make sure it looks right.

For AdSense within a post I use and recommend the AdSense Deluxe plugin, check out the guide for it here: How To Use The WordPress Plugin AdSense-Deluxe.



Tags:

Related posts

If you liked this post, feel free to leave a comment that is relevant to the post or subscribe to the feed and get future articles delivered to your feed reader.

Sorry but due to the spamming of a few all comments are moderated and will appear when approved and all drive-by comments will be deleted!

Comments

TQ for your nice info. Good Luck ?

Reply

I’m not sure if Google allow adsense and other text ads on the same page…

Reply

Adrian, I have multiple ads on several different sites with no issues for several years now. I know Google tries to dictate only three instances of ads per page, and not to have a page with ads showing rotating on traffic surfing sites. But I have never heard of them doing anything about multiple ad providers per page…

Reply

You write very well.

Reply

I use google adsense and infolinks text link ad in single page.

Reply

Can you have more than one adsense account.
I am new to this and I have bookmarked your site. Good info thanks

Reply

You made it easy. thanks you

is there a plugin or widget that allows me to do it without stuffing up the code.

Reply

There are many ready addons for using adsense.

Reply

Hi, be careful of using adsense in “box”, but yes good info from you, thx

Reply

Leave a comment
Drive-By comments will be deleted! Like "Thanks for sharing", "Nice post", or any other text that doesn't contribute to the discussion. If you ask a very specific question about your particular WordPress theme's code, it will probably be deleted. I can fix your WordPress site but for a price. If you ask a question like "Why don't my blog work right", it will be deleted. If you ask a question about your WordPress site without a leaving a link to it, it will be deleted. The point is to ask questions and or comment on the the actual content of the post, and to please use some common sense. All comments are moderated. Thank you.

(required)

(required)