1

I'm using the prettyPhoto API to open the the lightbox manually with the following code:

api_images  ['images/fullscreen/image1.jpg','images/fullscreen/image2.jpg','images/fullscreen/image3.jpg'];
api_titles = ['Title 1','Title 2','Title 3'];
api_descriptions = ['Description 1','Description 2','Description 3']
$.prettyPhoto.open(api_images,api_titles,api_descriptions);

The problem i'm facing is that the description values are pulling from Wordpress's WYSIWYG and the code is easily broken with random html tags, punctuation etc

  <script type="text/javascript">
    $(document).ready(function() {
        $('#menu-item-1006').on('click', function(e) {
            e.preventDefault();
            var images = new Array();
            var descriptions = new Array();
            var titles = new Array();
<?php
$i = 0;
$images = new WP_Query(array('post_type' => 'clearance', 'showposts' => -1, 'order' => 'menu_order', 'orderby' => 'ASC'));
if ($images->have_posts()) : while ($images->have_posts()) : $images->the_post();

        $featured = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
        ?>
                            images[<?php echo $i; ?>] = '<?php echo $featured[0]; ?>';
                            titles[<?php echo $i; ?>] =  '<?php the_title(); ?>'
                            descriptions[<?php echo $i; ?>] = '<?php echo get_the_content(); ?>';

        <?php
        $i++;
    endwhile;
else:
    ?>
<?php endif; ?>

            $.prettyPhoto.open(images, titles, descriptions);
        }) 
    });    
</script>

How can i filter the get_the_content() function so it will output w/o errors? Thanks!

3 Answers 3

1

a simple solution could be:

replace

<?php echo get_the_content(); ?>

with

<?php echo preg_replace('/\<[^\>]+\>/s', '', get_the_content()); ?>
Sign up to request clarification or add additional context in comments.

Comments

0

json_encode(get_the_content()) works!

Comments

0
$content = get_the_content();
echo strip_tags($content, '<a><img>');

will leave only a and img tags. I think it's all what you need for gallery

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.