简体   繁体   English

WordPress RSS Feed来自一个特定的短代码

[英]WordPress RSS Feed from one specific shortcode

I want to make function that will display RSS Feed content from one specific shortcode. 我想制作将从一个特定短代码显示RSS Feed内容的功能。 Example, I have: 例如,我有:

[text1]Text One[/text1]
[text2]Text Two[/text2]

Now, content of text2 shortcode should display in RSS Feed. 现在,text2短代码的内容应该显示在RSS Feed中。

Function I have so far: 到目前为止我的功能:

function custom_rss($content) {
if(is_feed()){
$content = "Custom Text";
}
return $content;
}
add_filter('the_excerpt_rss', 'custom_rss');
add_filter('the_content', 'custom_rss');

Ok, this works, I get "Custom Text" in the RSS Feed. 好的,这有效,我在RSS Feed中获得“自定义文本”。

What function will call content from specific shortcode, in example, from [text2]Text Two[/text2] . 什么函数将调用来自特定短代码的内容,例如,来自[text2]Text Two[/text2]

Wordpress Codex: Wordpress Codex:
shortcode atts and add_shortcode shortcode attsadd_shortcode

function bartag_func( $atts ) {
     extract( shortcode_atts( array(
          'foo' => 'no foo',
          'baz' => 'default baz'
     ), $atts ) );
     return "foo = {$foo}";
}
add_shortcode( 'bartag', 'bartag_func' );

Try this code: 试试这段代码:

function text( $atts, $content = null ) {
    if (is_feed()) {
        return $content;
    } else {
        return '<div class="text" style="display: block; margin-left: 160px;">'.$content.'<br><br></div>';
    }
}
add_shortcode( 'text', 'text' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM