1 回答
TA贡献1804条经验 获得超7个赞
你已经知道答案了。在“the_content”过滤器中,您将一些文本添加到 $content 变量中。现在你想要做的是追加。前任:
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 "Beginning text" .$content . "Ending Text";
}
return $content;
}
“开始文本”是您已经添加的文本。
[2020 年 1 月 7 日]:每个 OP 请求添加代码片段以根据 pos 类别进行更改。
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() ) {
//get categories
$categories = get_the_category();
foreach($categories as $category){
//you can check by term_id, name, slug
if($category->$term_id == $target_term_id){
return "Beginning text" .$content . "Ending Text";
}
}
}
return $content;
}
- 1 回答
- 0 关注
- 70 浏览
添加回答
举报