<?php if ( wp_get_attachment_image($item['image']['id'], 'home-post-thumbnail') !='' ) { ?> <?php echo wp_get_attachment_image( $item['image']['id'], 'home-post-thumbnail' ); } ?> <?php else { ?> <img class="img-responsive img-whp" src="<?php echo plugin_dir_url( __FILE__ ) . '/6-450x450.jpg'; ?>"> <?php } ?>
I get critical error.phpstorms says that expecting statements.I couldnt find a solution
Advertisement
Answer
You cannot “interrupt” the PHP code after the closing {
of the if
and before the else
keyword.
Cleaned up version:
<?php if (wp_get_attachment_image($item['image']['id'], 'home-post-thumbnail') != '') { echo wp_get_attachment_image($item['image']['id'], 'home-post-thumbnail'); } else { ?><img class="img-responsive img-whp" src="<?php echo plugin_dir_url( __FILE__ ) . '/6-450x450.jpg'; ?>"><?php } ?>
To avoid such errors, try learning and following a coding standard, e.g. PSR-12.
Since you are working with WordPress, here is WP’s coding standard for PHP: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/