skip to Main Content

I have Slick Slider built in with ACF in wordpress, the images and slider work, trying to now wrap the image in a link so each image can link out to a set page.
at the moment it just links to the home url, Im not sure what im doing wrong in the code, any help is useful.

  <h3 class="pb-3"><?php the_field('slider-text', false, false) ?></h3>
<div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?>">
    <?php if (have_rows('slides')): ?>
        <div class="slides"
             data-slick='{"slidesToShow": 5, "slidesToScroll": 1, "autoplay": true, "autoplaySpeed": 2000, "dots": true}'>
            <?php while (have_rows('slides')): the_row();
                $image = get_sub_field('image');
                $link = get_sub_field('link');
                ?>
                <div class="col">
                    <a href="<?php ($link['id']); ?>">
                    <?php echo wp_get_attachment_image($image['id'], 'full'); ?>
                    </a>
                </div>
            <?php endwhile; ?>
        </div>
    <?php else: ?>

    <?php endif; ?>
</div>

2

Answers


  1. Try: <a href="<?php echo esc_url( $link['id'] ); ?>">

    You need to print the url to display in the output, also added abit of sanitization for safe measure!

    Login or Signup to reply.
  2. Adding an answer from my comment:

    You aren’t doing anything with the (link['id']) – that’s why it’s redirecting to the same page it’s on – the href is empty.

    You need to pass that link ID into get_permalink()

    <a href="<?php echo get_permalink($link['id']); ?>">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search