通过functions.php添加的摘录-无法删除简码

时间:2018-08-22 16:42:05

标签: php wordpress post

我在functions.php 中有此代码(我用于按类别过滤帖子的ajax),问题是我无法从帖子摘录(摘录中)删除可视化作曲家短代码代码是

<?php $excerpt = get_the_excerpt($post); echo $excerpt; ?> 

我尝试了一堆脚本来删除短代码,但没有结果。任何帮助都会得到应用。

function remove_shortcode_from_excerpt($content) {
$content = strip_shortcodes( $content );
return $content;//always return $content
}
add_filter('get_the_excerpt', 'remove_shortcode_from_excerpt'); 

///Ajax post filtering by category
 add_action( 'wp_ajax_nopriv_load-filter', 'prefix_load_cat_posts' );
 add_action( 'wp_ajax_load-filter', 'prefix_load_cat_posts' );
 function prefix_load_cat_posts () { ?>
 <div class="allposts row blogrow">
 <?php ob_start ();
   $query = new WP_Query(
     $args = array (
    'showposts' => 999,
    'cat' => $cat_id = $_POST[ 'cat' ]
    )  );
   $posts = get_posts( $args );
     foreach ( $posts as $post ) {
     setup_postdata( $post );
 ?>

  <div class="functsingnews news-wrap">  
 <div class="newsflex">
 <div class="postfeat"> <?php if (has_post_thumbnail( $post->ID ) ): ?>
 <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'my-custom-thumb' ); ?>
 <img src="<?php echo $image[0]; ?>">
 <?php endif; ?> 
 </div>
 <div class="postinfo">
 <div class="postcat">
  <?php foreach( (get_the_category($post)) as $category) { ?> 
 <?php echo    $category->cat_name; ?><?php } ?>
 </div>
 <h4 class="newstitle"><?php echo $post->post_title; ?></h4>
<div class="postexc"><p><?php $excerpt = get_the_excerpt($post); echo $excerpt; ?></p></div>
<a href="<?php echo get_permalink; ?>">READ MORE <span     class="rightarrow"></span></a>
 </div>
</div>
</div>


 <?php
} wp_reset_postdata(); ?>
</div>
 <div class="next-button"><a href="#" id="loadMoreCat">Load More Posts CAT</a></div>

 <? $response = ob_get_contents();
ob_end_clean();

 echo $response;
die(1);
} 

function remove_shortcode_from_excerpt($content) {
$content = strip_shortcodes( $content );
return $content;//always return $content
}
add_filter('the_excerpt', 'remove_shortcode_from_excerpt');

1 个答案:

答案 0 :(得分:0)

好吧,如果有人需要此解决方案,我会找到解决方案:

<?php $excerpt = get_the_excerpt($post); echo $excerpt = preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $excerpt);  ?>