Title: Syntax Error in Conditional Custom Field Code
Last modified: August 19, 2016

---

# Syntax Error in Conditional Custom Field Code

 *  Resolved [LearnWebCode](https://wordpress.org/support/users/learnwebcode/)
 * (@learnwebcode)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/syntax-error-in-conditional-custom-field-code/)
 * Hi everyone,
 * I’m trying to have a bit of custom text (from a custom field) display, and if
   a page doesn’t have that custom field, than have a default/standby bit of text
   appear. Here is the code I’m using, and I’m receiving a “unexpected T_ENDIF” 
   syntax error. I’m a true beginner in PHP, so if it’s something obviously wrong(
   which I’m sure it is), please be kind 🙂
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
           <?php $pageHeader=get_post_meta($post->ID, 'pageHeader', true); ?>
           <?php if ( $pageHeader ) { ?>
   
           <!-- with custom page header -->
       	<?php echo $pageHeader; ?>
           <?php } else { ?>
   
           <!-- without custom page header -->
       	Sample code
           <?php endif; ?>
   
             <?php
       			if ( has_post_thumbnail() ) {
       			the_post_thumbnail();
       			}
       			?> 
   
       			<h1><?php the_title(); ?></h1>
       			<?php the_content(); ?>
   
       		<?php endwhile; endif; ?>
       ```
   
 * Any ideas? Any help is greatly appreciated.

Viewing 1 replies (of 1 total)

 *  Thread Starter [LearnWebCode](https://wordpress.org/support/users/learnwebcode/)
 * (@learnwebcode)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/syntax-error-in-conditional-custom-field-code/#post-1399883)
 * I discovered the problem.
 * In case any other PHP beginners have the same question/problem, here’s the fix.
 * The `<?php endif; ?>` after the “without custom page header” section should be
   removed, and in its place, add:
 * `<?php } ?>`

Viewing 1 replies (of 1 total)

The topic ‘Syntax Error in Conditional Custom Field Code’ is closed to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [field](https://wordpress.org/support/topic-tag/field/)

 * 1 reply
 * 1 participant
 * Last reply from: [LearnWebCode](https://wordpress.org/support/users/learnwebcode/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/syntax-error-in-conditional-custom-field-code/#post-1399883)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
