Support » Fixing WordPress » Twenty Eleven adsense troubleshoot

  • Hi,
    I’m using a TwentyEleven CHILD theme and I have added adsense elements to my site via widgets. This works fine.

    However, I would like to have one advert appear at the end of each post. I would like to do this for every post without pasting the adsense code in each time. So, I understand that I need to modify the single.php file to achieve this. Despite my best efforts and info out there on the web(usually for other themes), I’m getting errors.

    The code on my single.php is:

    [please mark any code using the code button – see ]

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

    Can anyone help me as to where I place the code or advise a better approach.

    Kind regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael


    Forum Moderator

    after this line would be a possibility:

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

    or in content-single.php;
    for instance after:

    </div><!-- .entry-content -->

    or after:

    </footer><!-- .entry-meta -->

    really depends on the exact location where you want to see the ads.

    Thanks alchymyth, I tried inputting it after get_template_part but still got the errors. My method is copying the single.php file from original themes folder, pasting the code( just the adsense code in between the <script> tags) and then uploading the file within the child theme. Is this sound practice?

    As for the location, I would like the advert to appear at the end of each post. What does the content-single.php file affect?

    Appreciate the help.



    Forum Moderator

    what errors exactly?
    can you post the full code of the single.php template including the adsense? ( how-to see )

    content-single.php is called by the ‘get_template_part()’ line, and does the display of the actual single post: title, content, postmetadata, etc.

    I get the ‘Server error message’ with the message ‘HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request.’

    Can anyone help with this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Twenty Eleven adsense troubleshoot’ is closed to new replies.