Hey guys. I have a weird issue here:
I’m trying to get Gallerys or images i posted in a custom content field to open with a lightbox. It works only for the default content box in the post. The one i created with custom fields doesn’t have the required rel=”lightbox” in its anchor tag.
How do i add this functionality?
You can check out an example here:
(i know the code is very messy, but it’s still in development)
Did you try using something like this in your custom theme page, I used fancybox:
<a class="fancybox" rel="group" href="<?php the_field('name_custom_field'); ?>"><img src="<?php the_field('name_custom_field'); ?>" alt="<?php the_title(); ?>"/></a>
It is most likely that you have a plugin which is adding the lightbox effect to WYSIWYG galleries. Is this correct?
if so, all you will need to do is pass the ACF value through the
the_content filter – this is how a plugin would modify the_content value.
<?php $wysiwyg = get_field('field_name', false, false); echo apply_filters('the_content', $wysiwyg); ?>
Please note the extra
false, false parameters are to prevent ACF from formatting the value because
the_content will also do this.
thank you for this suggestion, but it doesn´t work for me
<div class="entry-content"> <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'pictorico' ), 'after' => '</div>', ) ); ?> <?php if(get_field('spalten')): ?> <?php while(has_sub_field('spalten')): ?> <div class="columns"> <div class="col-left"><?php $wysiwyg = the_sub_field('linke_spalte', false, false); echo apply_filters('the_content', $wysiwyg); ?></div> <div class="col-right"><?php $wysiwyg = the_sub_field('rechte_spalte', false, false); echo apply_filters('the_content', $wysiwyg); ?></div> </div> <?php endwhile; ?> <?php endif; ?> </div><!-- .entry-content -->
I´m using a repeater field, are ther any other options?
Thank you very much
Hi @elliot, this solution didn’t work in my situation, unfortunately.
<?PHP $content = get_field('wysiwyg', false, false); echo apply_filters('the_content', $content); ?>
It destroys the output of the
wysiwyg, displaying nothing.
I have the plugin Simple Lightbox installed, which I want to use for the gallery’s lightbox.
Previously, I was using:
<?PHP the_sub_field('wysiwyg'); ?>
To output the
The topic ‘LightBox images in custom content field’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.