I changed the html code below
<a href="<?php echo pietergoosen_get_first_image() ?>" title="<?php printf( the_title_attribute( 'echo=0' ) ); ?>" rel="lightbox">
<?php echo pietergoosen_adjust_first_image(pietergoosen_get_first_image(), get_the_title(), 525, 0); ?>
</a>
to the function below as I need more than one image size with an if statement
function pietergoosen_the_excerpt_image_output() {
$firstImage = pietergoosen_get_first_image();
$imageAttribute = esc_attr(the_title_attribute( 'echo=0' ));
$title = get_the_title();
if (isset($classes) && $classes == 'custom-sidebar-per-page-width'){
$imageSize = '525';
} else {
$imageSize = '380';
};
printf(
'<a href="%1$s" title="%2$s" rel="lightbox"><pietergoosen_adjust_first_image(%1$s, %3$s, %4$d, %4$d)></a>',
$firstImage,
$imageAttribute,
$title,
$imageSize
);
}
I call the function like this
<?php echo pietergoosen_the_excerpt_image_output(); ?>
but the image now does not show up anymore. Any advice on how to fix it, please
Your printf() call is a total mess. It's got syntax errors and is utterly unecessary:
echo "<a href='{$firstImage}' title='$imageAttribute' etc....";
is all that's necessary.
With your version:
printf('<a href="%1$s" title="%2$s" rel="lightbox"><p
^--single quoted string
^^--- not a valid formatting char for printf
^^--- variables are NOT interpolated in '-quoted strings
A proper (and still unnecessary) printf() would've been
printf('a href="%s" title="%s" ...., $var1, $var2);
^^--insert a string
The ONLY time a printf/sprintf() call would be useful in PHP is if you need to do special formatting on an inserted character, e.g.
printf('%05d', 12); // outputs 00012
Your new function is not returning a value to echo, it is printing from within the function. The last line should be:
return sprintf(
'<a href="%1$s" title="%2$s" rel="lightbox"><pietergoosen_adjust_first_image(%1$s, %3$s, %4$d, %4$d)></a>',
$firstImage,
$imageAttribute,
$title,
$imageSize
);