WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Eleven adsense troubleshoot (6 posts)

  1. Jar Jar
    Member
    Posted 2 years ago #

    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 http://codex.wordpress.org/Forum_Welcome#Posting_Code ]

    <?php
    
    /**
    
     * 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,
    Jar.

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    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.

  3. Jar Jar
    Member
    Posted 2 years ago #

    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.

  4. alchymyth
    Forum Moderator
    Posted 2 years ago #

    what errors exactly?
    can you post the full code of the single.php template including the adsense? ( how-to see http://codex.wordpress.org/Forum_Welcome#Posting_Code )

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

  5. Jar Jar
    Member
    Posted 2 years ago #

    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.'

  6. Jar Jar
    Member
    Posted 2 years ago #

    Can anyone help with this?

Topic Closed

This topic has been closed to new replies.

About this Topic