0

I need to link some gallery images to external webistes. After some research I'm not able to found a solution that isn't using a plugin. Is this possible in wp without plugins?

NB: I don't want to use a plugin, my client don't want to have plugins installed!

Here is my code:

$args = array(
'post_type' => 'post',
'name' => 'partners'
);
$logo_img = new WP_Query( $args );
?>
<div class="container-fluid" id="">
  <div class="row" style="margin-top:1em;margin-bottom:1em;">
<?php if( $logo_img->have_posts() ): while( $logo_img->have_posts() ): $logo_img->the_post();
$logo_gallery = get_post_gallery_images( $post->ID );
if( $logo_gallery ): ?>
  <div class="col-sm-12 col-md-12 col-lg-12 text-center">
<?php foreach($logo_gallery as $logo ): ?>
    <img class="img-fluid" src="<?php echo $logo; ?>" alt="" width="60" id="partner-logo" style="margin:0 .5em 0 .5em;"/>
<?php endforeach; ?>
  </div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
  </div>
</div>

1 Answer 1

0

This is the exact plugin you need - https://wordpress.org/plugins/gallery-custom-links/

No code customizations needed.

For fixed image link (http://www.example.com):

$args = array(
'post_type' => 'post',
'name' => 'partners'
);
$logo_img = new WP_Query( $args );
?>
<div class="container-fluid" id="">
  <div class="row" style="margin-top:1em;margin-bottom:1em;">
<?php if( $logo_img->have_posts() ): while( $logo_img->have_posts() ): $logo_img->the_post();
$logo_gallery = get_post_gallery_images( $post->ID );
if( $logo_gallery ): ?>
  <div class="col-sm-12 col-md-12 col-lg-12 text-center">
<?php foreach($logo_gallery as $logo ): ?>
    <a href="http://www.example.com">
    <img class="img-fluid" src="<?php echo $logo; ?>" alt="" width="60" id="partner-logo" style="margin:0 .5em 0 .5em;"/>
    </a>
<?php endforeach; ?>
  </div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
  </div>
</div>
3
  • I don't want to use a plugin for this, I'm sure that there is a wp function that I can use to achieve this
    – sialfa
    Commented Oct 30, 2019 at 5:44
  • So you want to link all images to a fixed link like example.com or unique link for each image. If you want unique link for each image, then the plugin is recommended option but for fixed URL for all images, you can use the updated code.
    – Girish
    Commented Oct 30, 2019 at 6:28
  • I need different links, I will look to the source code of the plugin to see what filters or hook are used. The client don't allow me to use plugins.
    – sialfa
    Commented Oct 30, 2019 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.