Home › Forums › Front-end Issues › LightBox images in custom content field
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:
[link offline]
(i know the code is very messy, but it’s still in development)
Hi Flowbob,
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>
The problem is that i’m not only getting image URLs, i’ve got a field with a WYSIWYG editor which gives me all kinds of content, so i can’t hardcode it in my template :/
Hi @flowbob
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.
Thanks
E
I dont really understand what it does, but this seems to solve the issue 😉
Thanks Elliot, You’re awesome!
Am i right that it kind of marks the field as a “the_content” output for plugins i installed?
hi
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 -->
http://wp.bieblwerk.de/agentur/
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 wysiwyg
normally.
Help appreciated.
Steve
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.