Auto-add paragraphs to custom field?

hey guys,
is it possible to format text in a custom field input box automatically with paragraphs?

e.g. like the normal text-widget that has the option to say “auto-add paragraphs” when there is a linebreak.

I just want my blogauthors to spare typing
at the end of every line in a custom field!

is there a way to do so?

update:

<?php if (have_posts()) : ?>
                <?php while (have_posts()) : the_post();
                    $sidebar_title = get_post_meta($post->ID, 'sidebar-title', $single = true);
                    $sidebar_text = get_post_meta($post->ID, 'sidebar-text', $single = true); ?>

                    <?php if ( $sidebar_title !== '' && $sidebar_text !== '' ) { ?>
                        <li class="widget-container widget-light-blue custom">  
                            <h3 class="widget-title"><?php echo wpautop($sidebar_title, $br); ?></h3>
                            <?php echo wpautop($sidebar_text, $br); ?>
                        </li>
                    <?php } ?>

                <?php endwhile; ?>
            <?php endif; ?>

2 Answers
2

Why don’t you use apply_filters( 'the_content', $var ); when outputting your custom field? You don’t really want to save the extra paragraphs, otherwise you’ll end up seeing them when editing the custom field. This is not what happens with WordPress.

If you’re not happy with what the_content does (it does a lot of things including wpautop) then create a custom filter like this:

// Assuming $var is your custom field value
add_filter( 'my_custom_filter', 'wpautop' );
echo apply_filters( 'my_custom_filter', $var );

Cheers!

Leave a Comment