Mixmastermiike Mixmastermiike - 1 month ago 11
PHP Question

PHP syntax breaking the image tag

I am having an issue with my live site that works fine on a dev site (on a different host).

Essentially, it's brining in the image incorrectly and adding characters at the end... example:
https://www.idealhomeloans.com/wp-content/uploads/2016/08/refinance-1.jpg/%3E%20%3Cimg%20src=

it should just be: https://www.idealhomeloans.com/wp-content/uploads/2016/08/refinance-1.jpg

This is the php code I'm using to bring the image in...

<?php if( $image ): ?>


<?php
echo '<img class="'. $imagealigned.'" src="';the_sub_field('image');
echo '/>';

?>

<?php endif; ?>

<?php $image = get_sub_field('image');
//Checking if anything exists for the image field
if ($image) { ?>
<?php echo '<img src="';// display a sub field value
the_sub_field('image');
echo '/>';
?>
<?php } //if there is nothing for image then display
else { ?>
<?php }
?>


Can someone who knows PHP well take a look and see if there's something that would render the image tag to come in correctly?

Any guidance would be greatly appreciated!

Thanks

Answer

Perhaps if you actually LOOKED at the html you're generating, you'd see that you're generating BAD html:

echo '<img class="'. $imagealigned.'"     src="';the_sub_field('image');
                                              ^---start HTML attribute
echo '/>';
      ^----never end the attribute

So you're building

<img .... src="kittens.jpg>

and around and around the error merrygoround you go...

Comments