I tried to filter only the text in get_the_content for my home page, but its including my shortcode also, because in that page first row google map 2nd row text box i am using visual composer page builder.

My code

$content = get_the_content();
$content = apply_filters('the_content', substr(get_the_content(), 0, 60) );
$content = str_replace(']]>', ']]>', $content);
echo $content

My result

[vc_row][vc_column][vc_gmaps link=”#E-8_JTNDaWZyYW1lJTIwc3Jj


enter image description here

  • What are you trying to do exactly with the filter? At the moment your code is only grabbing the first 60 characters of the post, which is resulting in what looks like a broken shortcode. You'd probably be better off just replacing all of your code with the_content()
    – Tim Malone
    Apr 24, 2016 at 7:30
  • I just want to skip the sortcodes from the content. i want to display the 2nd row text. Apr 24, 2016 at 7:38
  • Ah got it. Just posted an answer for you :)
    – Tim Malone
    Apr 24, 2016 at 7:56

2 Answers 2


Based on your comment clarifying what you want to achieve, it appears you want to display the first 60 characters of your post not including any shortcodes.

To do this you can use the strip_shortcodes() function. Rewritten with that, your code will look like this:

$content = strip_shortcodes(get_the_content());
$content = apply_filters('the_content', substr($content, 0, 60) );
$content = str_replace(']]>', ']]>', $content);
echo $content;

All we're doing here is running the content (from get_the_content()) through strip_shortcodes() before applying Wordpress filters on the first 60 characters.

Depending on what you want to achieve and whether you're relying on any other plugins modifying this content for you, you actually might be fine to skip the apply_filters() call as well - in which case all you'd need to do is set $content to the substr() you want to have.

  • not working anyway thanks, for now i will use get_the_excerpt(). Apr 24, 2016 at 8:32
  • That's probably a better option if you're happy with it :)
    – Tim Malone
    Apr 24, 2016 at 21:50

You can use



  • 2
    Please file an edit] and explain why. Please first read How to Answer to get tips on how to write a good answer Jul 15, 2016 at 7:26

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.