WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [closed] Problem adding Adsense ads. (11 posts)

  1. satpan
    Member
    Posted 1 year ago #

    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?????

  2. riversatile
    Member
    Posted 1 year ago #

    Simple !
    Place the Google Adsense code into the single.php file (all post pages). But not on index.php file which is home page.

  3. satpan
    Member
    Posted 1 year ago #

    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:

    <?php
    /**
     * 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]

  4. riversatile
    Member
    Posted 1 year ago #

    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.

  5. satpan
    Member
    Posted 1 year ago #

    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.

  6. riversatile
    Member
    Posted 1 year ago #

    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

  7. satpan
    Member
    Posted 1 year ago #

    Thank You very-very much...
    It works great!!!!
    http://www.satpan.org

  8. riversatile
    Member
    Posted 1 year ago #

    You're welcome

  9. satpan
    Member
    Posted 1 year ago #

    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???

  10. ejortol
    Member
    Posted 1 year ago #

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

  11. Andrew
    Forum Moderator
    Posted 1 year ago #

    @ejortol,
    You can discuss that on your own thread.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags