I'm new to PHP. I'm working in a wordpress theme. I've installed a plugin <Photopress-Latest Images> that aims to display the latest uploaded images into the media library. It is working fine but I want the images href to be equal to a fixed adress (the photographs page of the wordpress theme) instead of the element (photo) page. The plugin seems to be simple (I say seems because I don't really know it) and I presume this is the code block I should change to apply the wanted behaviour:
while ( have_posts() ) { the_post(); $i++; $icon = sprintf( '(html %s class="%s")(html a class="nofancybox" href="%s")%s(html /a)(html /%s)', $icon_tag, $icon_class, get_attachment_link( $post->ID ), wp_get_attachment_image( $post->ID, $size ), $icon_tag );
As the html is not enabled into the code blocks in stack overflow the fifth line of the code above is weird (I've used parenthesis to define the beginin and ending of html blocks). When I try to change the href adress inside this code the plugin does not work anymore and instead of displayin the photograph it display some text.
Based on the sprintf, you will need to change either replace the %s in the href on the first line after the sprintf starts, AND remove get_attachment_link( $post->ID ) so that you do not have a mismatched count of paramaters needed (each %s requires a entry). e.g. while ( have_posts() ) {
the_post();
$i++;
$icon = sprintf(
'(html %s class="%s")(html a class="nofancybox" href="http://example.com")%s(html /a)(html /%s)',
$icon_tag,
$icon_class,
wp_get_attachment_image( $post->ID, $size ),
$icon_tag
);
OR you could simply modify get_attachment_link( $post->ID ) and make it a string.
while ( have_posts() ) {
the_post();
$i++;
$icon = sprintf(
'(html %s class="%s")(html a class="nofancybox" href="%s")%s(html /a)(html /%s)',
$icon_tag,
$icon_class,
"http://example.com",
wp_get_attachment_image( $post->ID, $size ),
$icon_tag
);
I hope that anwsers your question.