我正在尝试在帖子末尾添加自定义字段。
我使用下面提到的代码成功地显示了自定义内容。但主要帖子的内容被替换了:
function custom_content_filter_the_content( ) {
   the_field("field1");
}
add_filter( \'the_content\', \'custom_content_filter_the_content\' );
 因此,我想在下面提到的示例中进行尝试:
function custom_content_filter_the_content( $content ) {
    $custom_content = \'some_content_appears_here\';
    $custom_content .= $content;
    return $custom_content;
}
add_filter( \'the_content\', \'custom_content_filter_the_content\' );
 要替换
\'some_content_appears_here\' 具有
<span class="custom_fds"><?php if( function_exists(\'the_field\') ) the_field(\'field1\'); ?></span>. 
谁能告诉我怎么使用<?php the_field() ?> 具有in功能。php在帖子内容末尾添加自定义字段(使用高级自定义字段创建)(当我们在模板中使用而不是在functions.php中使用时,这很容易)?
Update: @G、 M的代码帮助我实现我想要的。
以下是最终代码:
function custom_content_filter_the_content( $content ) {
    if ( function_exists(\'get_field\') ) {
      $content .= \'<span class="custom_fds">\' . get_field(\'field1\') . \'</span>\';
      $content .= \'<span class="custom_fds">\' . get_field(\'field2\') . \'</span>\';          
    }
    return $content;
}
add_filter( \'the_content\', \'custom_content_filter_the_content\' );
 感谢@G.M.我有一些与自定义内容相关的问题。
我在单个功能中显示多个字段。这样可以吗有没有一种方法可以在任何位置选择自定义内容的位置,而不是文章的结尾或开头the_content ? 例如,如果我使用任何插件进行社交共享,它们会在同一位置显示内容,我想更改这两种自定义内容的位置
 
                    最合适的回答,由SO网友:gmazzap 整理而成
                    您可以简单地使用get_field 返回字段,而不是the_field 这与它相呼应。
function custom_content_filter_the_content( $content ) {
    if ( function_exists(\'get_field\') ) {
      $content .= \'<span class="custom_fds">\' . get_field(\'field1\') . \'</span>\';
    }
    return $content;
}
add_filter( \'the_content\', \'custom_content_filter_the_content\' );