如何在所有帖子的内容之前和之后添加一些HTML?

时间:2016-04-17 作者:Joe Huang

我想在之前添加以下html(&A);发布内容后:

<ol style = "padding:0;margin:0"> 
    // post content
</ol>
如何自动为所有现有帖子执行此操作?

1 个回复
SO网友:Pieter Goosen

利用the_content 滤器这样,您可以调整/添加/删除内容中的某些内容

add_filter( \'the_content\', function ( $content )
{
    // Make sure we only target the main query\'s content, adjust as needed
    if ( !in_the_loop() )
        return $content;

    // We are targeting the correct content, so lets add what we need to
    $new_content  = \'<ol style = "padding:0;margin:0">\';
    $new_content .= $content;
    $new_content .= \'</ol>\';

    return $content = $new_content;
});