我正在使用wp\\u trim\\u摘录,它工作得很好,但我想去掉该摘录中包含的链接(使用get\\u the\\u内容),我已经在网上查找并尝试了许多解决方案,以使其正常工作,希望有人能帮我找到正确的方向。
我的工作代码如下所示:
add_filter( \'wp_trim_excerpt\', \'my_custom_excerpt\', 10, 2 );
function my_custom_excerpt($text, $raw_excerpt) {
if( ! $raw_excerpt ) {
$content = apply_filters( \'the_content\', get_the_content() );
$text = substr( $content, 0, strpos( $content, \'</p>\' ) + 4 );
}
$text = preg_replace("/<img[^>]+\\>/i", "", $text);
$buttonmore = \'<p><a class="button right" href="\'. get_permalink($post->ID) . \'"> Read the full article...</a></p>\';
return $text . " " . $buttonmore;
}
不工作(我添加了strip\\u标记(get\\u the\\u content())
add_filter( \'wp_trim_excerpt\', \'my_custom_excerpt\', 10, 2 );
function my_custom_excerpt($text, $raw_excerpt) {
if( ! $raw_excerpt ) {
$content = apply_filters( \'the_content\', strip_tags(get_the_content()) );
$text = substr( $content, 0, strpos( $content, \'</p>\' ) + 4 );
}
$text = preg_replace("/<img[^>]+\\>/i", "", $text);
$buttonmore = \'<p><a class="button right" href="\'. get_permalink($post->ID) . \'"> Read the full article...</a></p>\';
return $text . " " . $buttonmore;
}