默认情况下,似乎所有超链接都从摘录中删除了。也许这是为了防止链路功率被稀释。
是否有方法允许在摘录内容中显示超链接?
默认情况下,似乎所有超链接都从摘录中删除了。也许这是为了防止链路功率被稀释。
是否有方法允许在摘录内容中显示超链接?
WordPress使用过滤器wp_trim_excerpt
剥离标签。您可以删除过滤器并创建自己的过滤器,从而允许链接:
<?php
function new_wp_trim_excerpt($text) {
$raw_excerpt = $text;
if ( \'\' == $text ) {
$text = get_the_content(\'\');
$text = strip_shortcodes( $text );
$text = apply_filters(\'the_content\', $text);
$text = str_replace(\']]>\', \']]>\', $text);
$text = strip_tags($text, \'<a>\');
$excerpt_length = apply_filters(\'excerpt_length\', 55);
$excerpt_more = apply_filters(\'excerpt_more\', \' \' . \'[...]\');
$words = preg_split(\'/(<a.*?a>)|\\n|\\r|\\t|\\s/\', $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE );
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(\' \', $words);
$text = $text . $excerpt_more;
}
else {
$text = implode(\' \', $words);
}
}
return apply_filters(\'new_wp_trim_excerpt\', $text, $raw_excerpt);
}
remove_filter(\'get_the_excerpt\', \'wp_trim_excerpt\');
add_filter(\'get_the_excerpt\', \'new_wp_trim_excerpt\');
资料来源:http://lewayotte.com/2010/09/22/allowing-hyperlinks-in-your-wordpress-excerpts/我希望在没有指定摘录并且帖子有密码保护的情况下修改\\u摘录的输出。我已经可以将受密码保护的表单修改为我想要的任何内容,但是\\u摘录输出“没有摘录,因为这是一篇受保护的帖子。”。此代码位于wp includes/post模板中。php:function get_the_excerpt( $deprecated = \'\' ) { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, \'