Support » Fixing WordPress » Problem adding Adsense ads.

  • Resolved satpan


    Hello freinds,
    I’m using WP 3.5 and Twenty-Twelve theme.
    I want to add adsense ads in all posts below post title but don’t want these ads to show on Home, any help?????

Viewing 10 replies - 1 through 10 (of 10 total)
  • Simple !
    Place the Google Adsense code into the single.php file (all post pages). But not on index.php file which is home page.

    Thanks riversatile,
    I tried it, but ad is showing above post title, what if i want to show it below post title

    sinlge.php code is this:

     * The Template for displaying all single posts.
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
    get_header(); ?>
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    			<?php while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'content', get_post_format() ); ?>
    				<nav class="nav-single">
    					<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
    					<span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'twentytwelve' ) . '</span> %title' ); ?></span>
    					<span class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'twentytwelve' ) . '</span>' ); ?></span>
    				</nav><!-- .nav-single -->
    				<?php comments_template( '', true ); ?>
    			<?php endwhile; // end of the loop. ?>
    		</div><!-- #content -->
    	</div><!-- #primary -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    [In future, wrap code using backticks please]

    OK… I can see this template is calling another template :

    <?php get_template_part( 'content', get_post_format() ); ?>

    So you can’t place the Google Adsense code here if you want to place it below the post title, because the post title PHP function is in the secondary template.

    Thanks again,

    I have also tried it in content.php.
    Ad is showing below title but also showing in home, is there any way??? I don’t have much knowledge of php.

    Certainly because content.php is also called in index.php (home)

    You can perhaps made a copy of content.php, call the file post-content.php, put the Google ad code in it and call the file post-content.php in your single.php file by doing this :
    replace this code
    <?php get_template_part( 'content', get_post_format() ); ?>
    by this code
    <?php get_template_part( 'post-content', get_post_format() ); ?>

    Like that, the Google ad should not appears in home.

    For more information about get_template_part

    Thank You very-very much…
    It works great!!!!

    You’re welcome

    I have one more question if you don’t mind.
    when i click on your username “riversatile” it redirect to your website.
    How can i link my website to my username???

    Hello. In which part of post-content.php place the adsense code?
    Thank you.

    Moderator Andrew Nevins


    Forum moderator

    You can discuss that on your own thread.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Problem adding Adsense ads.’ is closed to new replies.