Title: Insert code in index.php &amp; content.php
Last modified: August 30, 2016

---

# Insert code in index.php & content.php

 *  [caroline](https://wordpress.org/support/users/makeupedia/)
 * (@makeupedia)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/insert-code-in-indexphp-contentphp/)
 * I have problems inserting codes in index.php and content.php!
 * I want to insert php and other codes (e.g Google Adsense) in index.php?
 * I would like to insert this before endwhile but it doesn’t work:
 *  ` <?php if( $wp_query->current_post == 0 ) {
    ADSENSE CODE }?>`
 *     ```
       <?php if ( have_posts() ) : ?>
   
       			<?php if ( is_home() && ! is_front_page() ) : ?>
       				<header>
       					<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
       				</header>
       			<?php endif; ?>
   
       			<?php
       			// Start the loop.
       			while ( have_posts() ) : the_post();
   
       				/*
       				 * Include the Post-Format-specific template for the content.
       				 * If you want to override this in a child theme, then include a file
       				 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
       				 */
       				get_template_part( 'content', get_post_format() );
   
       			// End the loop.
   
       			endwhile;
   
       			// Previous/next page navigation.
       			the_posts_pagination( array(
       				'prev_text'          => __( 'Föregående sida', 'twentyfifteen' ),
       				'next_text'          => __( 'Nästa sida', 'twentyfifteen' ),
       				'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Sida', 'twentyfifteen' ) . ' </span>',
       			) );
   
       		// If no content, include the "No posts found" template.
       		else :
       			get_template_part( 'content', 'none' );
   
       		endif;
       		?>
       ```
   
 * **Content.php**
    How can I insert code after _‘the\_content( sprintf(‘_ but before
   the _“keep reading_” here:
 *     ```
       <div class="entry-content">
       		<?php
   
       			/* translators: %s: Name of current post */
       			the_content( sprintf(
                                      __('Keep reading %s', 'twentyfifteen' ),
       				the_title( '<span class="screen-reader-text">', '</span>', false )
       			) );
   
       			wp_link_pages( array(
       				'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Sidor:', 'twentyfifteen' ) . '</span>',
       				'after'       => '</div>',
       				'link_before' => '<span>',
       				'link_after'  => '</span>',
       				'pagelink'    => '<span class="screen-reader-text">' . __( 'Sida', 'twentyfifteen' ) . ' </span>%',
       				'separator'   => '<span class="screen-reader-text">, </span>',
       			) );
       		?>
   
       	</div><!-- .entry-content -->
       ```
   
 * Thanks for any help!!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Marios Alexandrou](https://wordpress.org/support/users/marios-alexandrou/)
 * (@marios-alexandrou)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/insert-code-in-indexphp-contentphp/#post-6820998)
 * I’m guessing you’re not using the right structure for PHP.
 * You use the <?php and ?> tags if you’re not already in a PHP block. If you’re
   in a PHP block, just write the PHP you want.
 * AdSense code is HTML and JavaScript so you need to insert it outside of a PHP
   block.
 * So the code you probably need is something like:
 * … more php code…
    if( $wp_query->current_post == 0 ) { ?> ADSENSE CODE <?php }…
   more php code…
 *  Thread Starter [caroline](https://wordpress.org/support/users/makeupedia/)
 * (@makeupedia)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/insert-code-in-indexphp-contentphp/#post-6821040)
 * Thank you Marios!
 * I didn’t understand that the opening and closing tag was mandatory in the end.
   It works fine now, glad for your help!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Insert code in index.php & content.php’ is closed to new replies.

## Tags

 * [content php](https://wordpress.org/support/topic-tag/content-php/)
 * [index.php](https://wordpress.org/support/topic-tag/index-php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [caroline](https://wordpress.org/support/users/makeupedia/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/insert-code-in-indexphp-contentphp/#post-6821040)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
