• I would like a custom meta field to take shortcode as input and render the output but the field just returns the shortcode verbatim – is it possible to accept and render the shortcode.

    This is my listing template code:

    		
    		$listing_template .= "\t\t\t" . '<% if ( contact ) { %>' . "\r\n";
    		$listing_template .= "\t\t\t" . '<p><%= contact %>' . __( 'CONTACT US', 'wpsl' ) . '</p>' . "\r\n";
    		$listing_template .= "\t\t\t" . '<% } %>' . "\r\n";
    

    In the backend I am adding a Gravity form shortcode but it is not showing the form only the actual shortcode.

    Thanks

Viewing 1 replies (of 1 total)
  • Hi there!

    The templating system in wp store locator will only render variables that have been specifically made available for the template, so do_shortcode won’t work as you expect. Instead, you can create such variable using the wpsl_store_meta filter, and then use that variable inside your template. Consider this silly example:

    add_filter( 'wpsl_store_meta', 'custom_store_meta', 10, 2 );
    
    function custom_store_meta( $store_meta, $store_id ) {
        
        $shortcode_output = do_shortcode('whatever');
        $store_meta['shortcode_output'] = $shortcode_output;
    
        return $store_meta;
    }

    With this filter in place, now we can use the ‘shortcode_output’ variable anywhere in your template:

    $listing_template .= "\t\t\t" . '<strong>url: <%= shortcode_output %></strong>' . "\r\n";

    I hope this makes sense to you.
    Regards,

Viewing 1 replies (of 1 total)
  • The topic ‘Use Shortcode in custom meta field’ is closed to new replies.