Firefog
Firefog

Reputation: 3174

WordPress Short-code inside a Post-meta text editor is not showing front end

I am using a simple shortcode to add line space or separator. I added this shortcode in my post meta field where we can add custom description but this shortcode is not extract on frontend

This is the text in my editor of that post meta

Have you been looking for a better, easier way to enjoy your favorite [linespace gap="30"] Introducing the beautifully simple, versatile and discreet don’t let its size fool you.

where [linespace gap="30"] is that shortcode

This is the output on frontend

 Have you been looking for a better, easier way to enjoy your favorite [linespace gap="30"] Introducing the beautifully simple, versatile and discreet don’t let its size fool you.

this is my code for the shortcode function

function linespace_gap_shortcode($atts,$content = null){
        $arg_s = shortcode_atts(
            array(
                'gap'=>'30',
            ), $atts, 'linespace' );
            
            //getting the values from shortcode
            $gap    =  $arg_s['gap'];
            ob_start();
    ?>
        <div class="clearfix separator-<?php echo $gap; ?>"></div>

    <?php 
    return ob_get_clean();

    }
    
  add_shortcode('linespace','linespace_gap_shortcode');

Upvotes: 0

Views: 116

Answers (1)

Frederic Fillon
Frederic Fillon

Reputation: 159

In my mind you need to add a do_shortcode() inside your template around your meta value.

Example :

$my_meta = do_shortcode(get_post_meta( 0, 'meta_key', true ));

NB : think about esc_html() inside your shortcode function or force $gap to be an integer for better security .

Upvotes: 1

Related Questions