【问题标题】:How to Put Some Text in every Post Content on WordPress Automatically?如何在 WordPress 上的每个帖子内容中自动添加一些文本?
【发布时间】:2020-04-18 22:57:55
【问题描述】:

我希望每个帖子都必须在每个帖子赞模板中包含此内容。例如:

我的帖子标题:时间管理 帖子内容:【朋友们,我们的“Post-Title”文章怎么样。你喜欢它?如果有任何疑问,请不要忘记在下面发表评论。如需更多关于“Post-Title”的文章,请订阅我们。]

我希望它自动放在文章末尾的每个帖子中。 请帮我。如果有人知道的话。

【问题讨论】:

    标签: wordpress posts


    【解决方案1】:
    add_filter( 'the_content', 'filter_the_content_in_the_main_loop' );
    
    function filter_the_content_in_the_main_loop( $content ) {
    
        // Check if we're inside the main loop in a single post page.
        if ( is_single() && in_the_loop() && is_main_query() ) {
    
           return esc_html__("So Friends, How is our Article of ".get_the_title().". Do You Like it? Don't Forget to Comment below if Any Queries. For More Article regarding ".get_the_title()." Subscribe Us.").$content;
        }
    
        return $content;
    }
    

    【讨论】:

    • 您也可以创建自己的模板并将相同的模板分配给特定的帖子
    • 我正在尝试将一些文本加粗“”并添加 h2“

      ”代码,但代码不起作用。

    • 使用 _e() 代替 esc_html()
    猜你喜欢
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多