Shortcode for Wordpress

1

I'm using the IP API for geolocation in a wordpress plugin, the plugin is ready and works normally! I want to add the following:

In one of the fields of the plugin, the user can insert a text and at the end of this text, only this field does not accept shortcode, is a common text field type, without editor or anything, I will attach the image. The shortcode is ready, I just need the field to accept the shortcode, for now it only brings the shortcode as text.

Output Code

$loop_link_rows .= '<div class="coluna_relacionados_fake"><a rel="nofollow" target="_blank" href="/?action=count&id=' . $row->meta_id . '"><img src="'.content_url().'/uploads'.$row->meta_attachment.'" alt="'.esc_attr( stripcslashes($row->meta_title)).'"></a><a rel="nofollow" target="_blank" href="/?action=count&id=' . $row->meta_id . '">'.$row->meta_content.'</a></div>';

    
asked by anonymous 14.11.2016 / 17:30

1 answer

0

For the shortcode to work you need to call a filter, or activate it directly.

The simplest way is to call the the_content filter, which applies all filters defined for the content, including activating shortcodes. It works best if you have text along with the shortcode.

// Supondo que sua meta-key seja "chave"
$meta_value = get_post_meta( $post->ID, 'chave', true );
echo apply_filters( 'the_content', $meta_value );

The other way is to call do_shortcode() directly.

// Supondo que sua meta-key seja "chave"
$meta_value = get_post_meta( $post->ID, 'chave', true );
echo do_shortcode( $meta_value );

Applying in code:

$loop_link_rows .= '<div class="coluna_relacionados_fake">
    <a rel="nofollow" target="_blank" href="/?action=count&id=' . $row->meta_id . '">
        <img src="'.content_url().'/uploads'.$row->meta_attachment.'" alt="'.esc_attr( stripcslashes($row->meta_title)).'">
    </a>
    <a rel="nofollow" target="_blank" href="/?action=count&id=' . $row->meta_id . '">'
        .apply_filters( 'the_content', $row->meta_content ).
    '</a>
</div>';
    
14.11.2016 / 17:56