How do I Correct Uncaught Error / Syntax Error in Wordpress?

Hello, I’m new to coding and working on customizing my first child theme in Wordpress. I was able to successfully upload but have run into an error that is not allowing me to customize. I’ve reviewed the code to make sure the loops are closed but I’m unable to clearly identify the issue? Would appreciate more experienced eyes! I’ve included the error message and a screenshoot of the code. Big thanks!

Uncaught Error : syntax error, unexpected ‘endwhile’ (T_ENDWHILE) in /Applications/MAMP/htdocs/Reinvented Site Files/wp-content/themes/brooklyn/index.php on line 65

  • require_once()
  • require()

There has been a critical error on your website.

Screen Shot 2020-04-17 at 4.23.41 PM|690x486


Have a look at line 55:

</a><? } ?>

Should be </a><?php } ?>

May I suggest some improvements for readability?

<div class="sliderborder">
<section class="center slider">


    $page = get_page_by_title('Blog Slider Options', 'option');
    $ID = $page->ID;
    $counter = 1;

    if (have_rows('blog slider', 'option')):

      while (have_rows('blog slider', 'option')): the row();

        $image = get_sub_field('image');
        $alt = get_sub_field('alt');
        $posttype = get_sub_field('posttype');
        $title = get_sub_field('title');
        $link = get_sub_field('link');

        $even = ($counter % 2 == 0) ? true : false;


    <img src="<?= $image['url'] ?>" alt="<?= $alt ?>">
      <?php if ($link): ?>
        <a href="<?= $link ?>">
          <span class="slick-slug"><?= $posttype ?></span>
          <span class="slick-post-title"><?= $title ?></span>
      <?php endif; ?>





In order to be consistent, I’ve used the format

if ():


while ():

Also –take it or leave it kind of advice–, don’t hesitate to give your code ample white space. It’ll be easier to read and debug. Especially when you’re mixing logic with views, as is often the case in WordPress.

I’ve also turned your if / else statement for $even into a ternary operator. Cleaner.

Finally, I’ve used <?php ?> for logic and the short echo tags for display <?= ?>, so you straight away notice what should be considered logic and what should be considered display. Just my two cents, though.

Just in case:

<?php echo $variable; ?> is the same thing as
<?= $variable ?>

Hope this helps and good luck on your child theme :wink:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.