Automatically Inject AdSense Ads After Intro Text |
|
According to Google, the most effective placement for AdSense ads is directly in your content. Click through rates (CTR) are much higher for ads embedded in your content than banner ads or sidebar ads. The standard Joomla content component combines each article's intro text and main text, which means you don't have an opportunity to run a plugin or component to automatically insert your ads after the intro text. Fortunately I have come up with a method using the JosReplace component and a small hack to Joomla's content component which will allow you to do this.
We are going to accomplish this by hacking Joomla's content component to insert a replaceable text string in between the intro text and main text of each article when the full article is displayed. Then we will use a text replacing component to insert the Google AdSense ads. I use this method on PatrickSwesey.com. This is a site I've had for a few years and don't really update any more. There are a few pages that get a decent amount of Google search traffic and I want to monetize those hits, but I definitely don't want to spend time going through every single article to add AdSense code, and we won't have to after following this tutorial. Let's get started. First you will need to download, install and enable both the JosReplace component and JosReplace plugin, which use regular expressions (regex) and string matching to replace any text in your content with another text. Next you'll need to set up the JosReplace component. We need to create a new JosReplace item in the component's Configuration page. In your backend, go to Replace -> Configuration, then click New. The first text box is the string the component will search for. For this tutorial we will use {adsense_after_intro} but you can use any string you wish. The text area box below it is the text to replace the search string with. Here you will need to insert your Google AdSense code. You'll need to login to your Google AdSense account and create an ad unit, or get the code from an existing ad unit. I would suggest using a large or medium rectangle (as used in the content here on JoomlaDigger.com), these have the highest click through rates (CTR) for ads embedded directly in content. You will also get a higher cost per click (CPC) if you enable both Text and Image ads because you allow for more types of ads to compete for your ad spot. Create the AdSense ad, copy the JavaScript code and insert it into the JosReplace text area box. You may want to surround the AdSense code with a paragraph tag for better spacing: <p><JavaScript code> // Code </JavaScript></p> Now there are four radio buttons below that. Set these to Yes, No, No, Yes. This will enable this JosReplace item, replace the search text even if another word is touching it, it won't care about accidental capitalization, and will always remove the search string so your visitors will never see {adsense_after_intro} even if this JosReplace item is disabled.
The last part of the JosReplace component we need to look at is the Pages/Items multi-combo box on the right. You can either leave this set to "All" to show the same AdSense ad unit in every article, or you can choose which menu items to enable it for. If you wanted to place different ad units with different channels or sizes for each content section or category, you could choose the section or category here - then create more JosReplace items with the same search string and different AdSense code and choose a different section or category for each item. Now that your website is ready to insert your AdSense ads we'll need to modify your Content component to insert {adsense_after_intro} in between an article's intro text and main text. Open the content.php file located on your server under the components/com_content/ directory. Look for this code around line 1712: $row->text = $row->introtext. ( $params->get( 'intro_only' ) ? '' : chr(13) . chr(13) . $row->fulltext); Change it to the following:
$row->text = $row->introtext. ( $params->get( 'intro_only' ) ? '' : chr(13) .
chr(13) .'{adsense_after_intro}'. $row->fulltext);
You're done! Now you never have to worry about placing AdSense code in your content again, it will automatically be added after the intro text of every article. You can also replace the search strings with any other ad code or content. Keep in mind that this was a hack. If you upgrade your version of Joomla the content.php file might be overwritten. Hacking this file isn't the best solution for every website, but it worked well on PatrickSwesey.com because I had a over one hundred articles and I didn't want to edit every single article. If you don't currently have too many articles and you don't mind doing a tiny bit of extra work every time you write a new article, you should avoid this hack and simply place the {adsense_after_intro} directly at the top of your main text, or anywhere else in your content item (this is what I do for articles here on JoomlaDigger.com). Remember that Google doesn't allow you to place more than three AdSense for content ads on a single page and your account may be banned if you place four or more ads on one page.
|


Subscribe to the RSS Feeds















