Home>

The short code is displayed as it is in the article excerpt part of the site, and I want to hide it.
If i make the shortcode work, the caption image will be displayed, so it is ideal to hide only the shortcode part.

I think that I am controlling the article excerpt below, so I would like to add a description here.

// Original excerpt article -------------------------------------------- ------------------------------------
function new_excerpt ($a) {
 if (has_excerpt ()) {
   $base_content = get_the_excerpt ();
   $base_content = str_replace (array ("\ r \ n", "\ r", "\ n"), "", $base_content);
   $trim_content = mb_substr ($base_content, 0, $a, "utf-8");
 } else {
   $base_content = get_the_content ();
   $base_content = preg_replace ('!<Style. *?>. *?</Style. *?>! Is','', $base_content);
   $base_content = preg_replace ('!<script. *?>. *?</Script. *?>! Is','', $base_content);
   $base_content = strip_tags ($base_content);
   $trim_content = mb_substr ($base_content, 0, $a, "utf-8");
   $trim_content = mb_ereg_replace ('','', $trim_content);
 };
 echo $trim_content.'…';
};
// Remove the P tag from the excerpt
remove_filter ('the_excerpt','wpautop');
It was written that strip_shortcodes should be used, but PHP is refreshing for beginners.

I would like to know how to write the short code from the above code to hide it.

  • Answer # 1

    uppernew_excerpt ()Is used in some template.

    $base_content = strip_tags ($base_content);


    This part

    $base_content = strip_shortcodes ($base_content);
    $base_content = strip_tags ($base_content);


    How is it?

    By the wayArticle excerpt partThat means that the first part of the content (body) is displayed as an excerpt with the specified number of characters.

  • Answer # 2

    https://ja.thewordcracker.com/scribblings/how-to-remove-shortcodes-in-wordpress-excerpts/

    By the way, when I tested it, it was hidden even by the method on this site.
    I don't use it because I don't understand the theory, but if it helps.