Archived

This topic is now archived and is closed to further replies.

  • 0

Adsense Displayed on Home Page, First Two Posts Only

Question

Posted · Report post

There have been a lot of examples of code for displaying advertisements in WordPress. I can't seem to get them to work within the functions.php/framework configuration. I'm a noob so wouldn't mind someone explaining it like I'm five.

 

Plugins I have found didn't display advertisements on the home page/blog page, only on posts.

If someone knows of a plugin that will allow this, even better.

 

Right now I have a function/hook that is displaying under every excerpt and that doesn't look good when google only displays 3 adverts and my tower isn't being displayed.

 

Thanks

Share this post


Link to post
Share on other sites

15 answers to this question

Posted · Report post

Manoj

 

I understand your frustration, but please understand this request is an extreme customization.  It is very easy for us to provide, via the forum, the mechanism to add Google AdSense code to your site.  But to have the code inserted so that it displays on specific posts is something you really must hire a professional developer for.  It is not something we can assist with for the simple reason that you're talking about something to do with the management of the loop, not the design or layout of the site.  Since this is a WordPress issue, i'm compelled to refer you to our Pros.

 

Also, I realize you're not going to be pleased with that recommendation, so I'll respectfully suggest in that case, modification of your requirement so that the ads can display on a global basis, as WordPress is designed.  Again, this isn't a limitation placed by PageLines, but it is also something we can't support.  Nonetheless, one of our professionals may be able to assist, or another pro developer familiar with the WordPress loop might be helpful.

Share this post


Link to post
Share on other sites

Posted · Report post

but this function doesn't do anything when added in functions.php (in pagelines customize plugin).

 

Simon, we would appreciate if you can tell us how to show ads after two post (or three or four and so on) excerpts on homepage. 

 

Thank you!

Share this post


Link to post
Share on other sites

Posted · Report post

Install free action map plugin to get a visual map of all the hook locations then get the hooker plugin to add your hooks.

Be the best few dollars ever spent trust me ;)

Share this post


Link to post
Share on other sites

Posted · Report post

@Simon_P

 

Thanks for the quick reply. I've installed the Action Map plugin, great idea but I think my build is conflicting with the plugin. I have BBPress and BuddyPress installed as well as the White Label CMS plugin which removes the WordPress logo from the top left of the screen. The Action Map plugin says that the on/off function is in the top left, so I'm not sure if that is where it would normally drop down or not.

 

Edit: So, I disabled the WhiteLabelCMS Plugin which didn't make any option for ActionMap appear.

Edit2: ugh... As par for the course, I used the Pagelines Store to download the plugin which threw it into the plugins directory but doesn't automatically activate it and I didn't go into the plugins directory to activate it, so of course, no function. derp.

Share this post


Link to post
Share on other sites

Posted · Report post

It adds a button to the normal wp admin menu bar

Share this post


Link to post
Share on other sites

Posted · Report post

Ah, I guess I'll keep looking. All these two things do is point to where something should go, but the code I've seen everywhere doesn't seem to work within the functions.php customization plugin, at least, not as is. So, it isn't so much as where something should go, but what needs to go where.

Share this post


Link to post
Share on other sites

Posted · Report post

Action Map plugin was intended to help you identify the location of anything you wish to modify in a post/page layout.

 

Simon also mentioned the Hooker Plugin, a new premium product, which allows you to select the hooks from a drop down list, then paste code that's to be added to that hook. Hooker then writes the customized code correctly, for you. Once the hook is written, you can disable Action Map plugin entirely.

 

The question of what needs to go where is not quite as enduring as the mysteries of the Pyramids, but it's getting there!  Depending on what you're hoping to add, if you have the code, Hooker provides you the chance to simply paste it and go.  It's perfect, for example, for ads going into the header's branding section or contact info with linked phone numbers.

 

As for the display of ads on the first two posts only,  being an Adsense publisher for more than a decade, I'm unclear why you'd want to do this.  Adsense depends on several factors, including views and impressions.  The more views; the more likely you'll get impressions. This is your conversion rate.  These are usually very small, often fractions of one percent.  You really don't want to limit the opportunities for visitors to see your ads.

 

My recommendation is to place at least two Adsense code instances (the maximum allowed is three) on each and every page or post, above the fold (meaning, before the visitors have to scroll down).  One in the header's Branding area (a leaderboard works nicely here) and in the sidebar, a 336px wide ad is very effective.

Share this post


Link to post
Share on other sites

Posted · Report post

I honestly can't figure out how to respond to being sold on a plugin that doesn't answer my question, and then a remedial adsense course that asks why I would want to only put an advertisement under the first two posts and then answers it in the very next paragraph. It is like you two aren't reading the inquiry. I know what I want to do. I know where it should go. The way that Pagelines Framework is set up is keeping me from injecting the code that counts the first two entries and puts an advertisement under the excerpt. That's it. I can do it on the default WP install and theme... can't do it on Pagelines Framework. That is why I came to the forums to see if anyone has experience in doing such, but I'm being sold on a plugin. Oh well.

Share this post


Link to post
Share on other sites

Posted · Report post

As you probably know PageLines isn't setup like an ordinary Wordpress theme. If you wish to insert adsense onto your homepage and the first two posts, you will need to follow the instructions provided by Simon and use the ActionMap plugin to identify the correct location.

 

http://support.pagelines.me/docs/plugins/action-map/

Share this post


Link to post
Share on other sites

Posted · Report post

It would be great if can share the hook and function...I already tried all the available hooks for that location..but it doesn't work. I raised similar issue few months back and all I got an answer was...contact pageline pros. At least the framework must provide all the features that basic installation of wordpress provides.

 

Quick help is appreciated!

Share this post


Link to post
Share on other sites

Posted · Report post

Do a search for Adsense and you will find a post I replied to with some code to put Adsense in the first post only, it can be adapted I'm sure.

Share this post


Link to post
Share on other sites

Posted · Report post

Simon, i don't want to use any plugins..I already cleared in my query ...

Share this post


Link to post
Share on other sites

Posted · Report post

Manoj,

 

The Action Map plugin is intended solely to identify the location of things in posts or pages. It is a development tool, not a plugin for the placement of Adsense code. Kindly understand we're trying to help you with this issue and not to push plugins.  If you don't wish to use it, you're more than welcome to source through thousands of lines of code to find the correct place. Action Map makes it easier.

 

The Hooker Plugin is a very inexpensive means of saving you a great deal of time and trouble implementing your Adsense code, once the hook is identified.  Again, no one's forcing or pushing you to use or purchase anything,  but we're offering you solutions.  I'm unsure why you're unhappy with these suggestions, but you're more than free to do things manually with the child theme or pagelines-customize functions.php file.

 

We do want you to be a happy customer.

Share this post


Link to post
Share on other sites

Posted · Report post

When did I said I don't intend to use Action Map plugin? I said I already tried but could not identify the right hook. This was the solution you suggested - which requires two plugins. 

 

But I do not want to use these two plugins..

 

 

 

In cases such as this, I'm afraid such a customization takes the help of a Pro because trying to break into the loop can cause harm to your site.  So, I'd refer you to www.pagelines.com/pros

 

On the flip side of that, What I have done in past is to use Special Recent Posts plugin and the WP-Boxer plugin.  This would allow you to emulate the loop using customized shortcode you create yourself and some easy CSS.   Both plugins are free, but have premium versions at CodeCanyon.net.

 

Place Special Recent Posts shortcode on a static homepage for the 1st two posts. You may have to use CSS to resize the thumbnail, but it's very easy to do. 

 

Below it, using the Boxer plugin, which creates content blocks, insert the shortcode for a block-set.    The block set has one box, and it contains the AdSense code.

 

Following this, more shortcode for Special Recent Posts, this one offsetting the post list by 2, and displaying 8 or whatever number you'd like.

 

So, the page would have

  • 2 posts
  • ad
  • 8 posts

 

That seemed to be the layout you were seeking.

 

Note: If you were going to style the ads, such as centering, you can still do so with the content block.  Simply wrap the code in a unique class and use CSS to align the ad as desired. You may also be able to achieve this with the settings of Boxer plugin.

 

 

Share this post


Link to post
Share on other sites

Posted · Report post

As I mentioned earlier, this post is almost the same and you could easily adapt the code: http://www.pagelines.com/forum/topic/24039-add-adsense-code-on-homepage-after-two-post-counts/#entry140442
 
In that example the user required the adsense to only be displayed on the 2nd post, but you want it on post 1,2 and 3 so you just need to change the math..



add_action('pagelines_loop_after_excerpt', 'after_first_post_ad');
function after_first_post_ad($post_count) {
    if (is_home()) {
    global $post_ad_count;
    if ( ! isset( $post_ad_count ) )
        $post_ad_count = 1;
    if ( $post_ad_count < 4 ) { ?>
<!-- GOOGLE AD CODE START HERE -->
<script type="text/javascript"><!--
google_ad_client = "ca-pub-34XXXXXXXXXXXXXXX";
/* Top-Sidebar-300x250*/
google_ad_slot = "4089184913";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googl...ead/show_ads.js">
</script>
<!-- GOOGLE AD CODE ENDS HERE -->
<?php
    }
$post_ad_count++;
}
}

 

Share this post


Link to post
Share on other sites