我想删除[…]从RSS提要小部件。
我已尝试向函数添加以下内容:
function replace_ellipsis($text) {
$return = str_replace(\'[...]\', \'-\', $text);
return $return;
}
add_filter(\'get_the_excerpt\', \'replace_ellipsis\');
但是,这不会影响小部件。有什么帮助吗?
我想删除[…]从RSS提要小部件。
我已尝试向函数添加以下内容:
function replace_ellipsis($text) {
$return = str_replace(\'[...]\', \'-\', $text);
return $return;
}
add_filter(\'get_the_excerpt\', \'replace_ellipsis\');
但是,这不会影响小部件。有什么帮助吗?
这里有一个建议:
首先,我们针对具有摘要的RSS小部件wp_trim_words() 在wp_widget_rss_output()
函数,以删除[…]
零件
首先,我们删除wp_trim_words()
如果正在运行,则在显示当前小部件之前进行筛选。我们可以通过widget_display_callback
. 这意味着我们的过滤器回调将不会在下一个小部件中激活。
然后,我们通过dynamic_sidebar_after
钩这意味着过滤器回调将在动态侧栏之后删除。例如,如果动态侧边栏中只有一个小部件,那么这可能会很有用。
以下是演示插件:
add_filter( \'widget_display_callback\', function( $instance, $obj, $args )
{
// Cleanup before each widget
if( has_filter( \'wp_trim_words\', \'wpse_replace_hellip\' ) )
remove_filter( \'wp_trim_words\', \'wpse_replace_hellip\' );
// Target RSS widgets with summary
if(
\'rss\' === $obj->id_base
&& isset( $instance[\'show_summary\'] )
&& 1 == $instance[\'show_summary\']
) {
// Replace the […] part
add_filter( \'wp_trim_words\', \'wpse_replace_hellip\' );
// Clean up after dynamic sidebar
add_filter( \'dynamic_sidebar_after\', \'wpse_extra_cleanup\' );
}
return $instance;
}, 10, 3 );
function wpse_replace_hellip( $text )
{
if ( \' […]\' == substr( $text, -11 ) )
$text = substr( $text, 0, -11 );
return $text;
}
function wpse_extra_cleanup()
{
remove_filter( current_filter(), __FUNCTION__ );
remove_filter( \'wp_trim_words\', \'wpse_replace_hellip\' );
}
希望您能进一步测试并根据您的需要进行调整!的主体default RSS widget 由函数生成wp_widget_rss_output
. 正如您在源代码中看到的[...]
硬连线到代码中,并直接回显。没有用于直接操作提要输出的过滤器。
我试图使用EmbedRSS插件,但我使用php代码将其放入索引中。php文件无法工作。 [cetsEmbedRSS id=\'http://deannaschneider.wordpress.com\' itemcount=\'2\' itemauthor=\'1\' itemdate=\'1\' itemcontent=\'1\'] 转换为php: <?php echo do_shortcode (\'[cetsEmbedRSS id=\'http://deannaschneider.w