0

I am using this code to add to my posts a meta description from a custom field.

$des = get_post_meta( get_the_id(), 'fl_description', true);
  if( ! empty( $des )  ){
    $meta_des = esc_html($des);
    echo '<meta name="description" content="' . $meta_des . '" />';

However, I need to completely escape all html tags and shortcodes. i.e the input

<p><span class="x-dropcap">D</span>esigned by interior mastermind Chams it is one of the only top <strong>members</strong> clubs where partying and dining co-exist under one roof. </p>

needs to become:

Designed by interior mastermind Chams it is one of the only top members clubs where partying and dining co-exist under one roof. 

1 Answer 1

0

To strip HTML tags and shortcodes, use a combination of PHP's strip_tags ( http://php.net/manual/en/function.strip-tags.php ) and WordPress's strip_shortcodes ( https://codex.wordpress.org/Function_Reference/strip_shortcodes )

$meta_des = strip_shortcodes( strip_tag( $des ) );
1
  • strip tag works !
    – JoaMika
    Commented Aug 23, 2016 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.