• Resolved taskemann

    (@taskemann)


    Hi,

    I have a function which is the post’s long description, and this is the function’s code which is located in single.php (Single Post):

    <p id="long-desc"><?php echo get_post_meta($post ->ID, 'long-desc',true); ?></p>

    But the problem is that when I write the long description in its custom field, I need to add the paragraphs or the linebreakers manually with HTML to the custom field, it won’t do it automatically.

    But now I’ve found a function which should do this autmatically for me. It’s called for ‘wpautop’. You can read more about the function here: https://codex.www.ads-software.com/Function_Reference/wpautop

    But how do I add its code <?php wpautop( $foo, $br ); ?> to my long description’s function code <p id="long-desc"><?php echo get_post_meta($post ->ID, 'long-desc',true); ?></p> ?

    I’ve tried to “merge” these two codes in a lot of different ways, but I can’t get it to work.

    Thanks & best regards,

    Jimmy

Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php
        $myLongDescription = get_post_meta($post ->ID, 'long-desc',true);
    ?>
    <p id="long-desc">
        <?php echo wpautop( $myLongDescription, false ); ?>
    </p>
    Thread Starter taskemann

    (@taskemann)

    Thanks!

    But what’s $myLongDescription? Do I need to replace it with something or define it somewhere?

    I’m kinda php newbie.

    Regards,

    Jimmy

    <?php
    //  so you declare a new variable here called $myLongDescription
    //  then assign to it whatever the get_post_meta function returns
    
        $myLongDescription = get_post_meta($post ->ID, 'long-desc',true);
    ?>
    <p id="long-desc">
    //  and here is the wpautop formatting the string
        <?php echo wpautop( $myLongDescription, false ); ?>
    </p>
    Thread Starter taskemann

    (@taskemann)

    Ok thank you so much x500.net for your help. I’ll test it out within the day and see if I’m able to get it to work.

    Jimmy

    Thread Starter taskemann

    (@taskemann)

    Yup,

    I have the paragraphs now in the source code. But to make them visible I guess I need to play around with the paragraphs’ CSS code a bit.

    Thank you x500.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Auto adding paragraphs to custom fields with 'wpautop'?’ is closed to new replies.