文章目录
本文最后更新于 2022-10-14,已超过 365 天未更新,内容可能已失效。

在文章开头添加固定内容

add_filter('the_content', 'add_zm_content_beforde');
function add_zm_content_beforde( $content ) {
	if( !is_feed() && !is_home() && is_singular() && is_main_query() ) {
		$before_content = '在文章内容开头添加固定内容';
		$zm = $before_content . $content;
	}
	return $zm;
}

 

在文章末添加固定内容

add_filter('the_content', 'add_zm_content_after');
function add_zm_content_after( $content ) {
	if( !is_feed() && !is_home() && is_singular() && is_main_query() ) {
		$after_content = '在文章内容末尾添加固定内容'; 
		$zm = $content . $after_content;
	}
	return $zm;
}

 

同时添加

add_filter('the_content', 'add_zm_content_before_and_after');
function add_zm_content_before_and_after( $content ) {
	if( !is_feed() && !is_home() && is_singular() && is_main_query() ) {
		$after_content = '在文章内容末尾添加固定内容'; 
		$before_content = '在文章内容开头添加固定内容';
		$zm = $before_content . $content . $after_content;
	}
	return $zm;
}

 

指定添加

add_filter('the_content', 'add_zm_content_after_mac_custom_post_type');
function add_zm_content_after_mac_custom_post_type( $content ) {
	if (is_singular( "mac" )){
		$new_mac_content = '只在自定义帖子类型“mac”文章末尾添加固定内容';
		$aftercontent = $new_mac_content;
		$zm = $content . $aftercontent;
		return $zm;
	} else {
		return $content;
	}
}

 

CC 许可协议
署名-非商业性使用-相同方式共享 4.0 国际 了解协议
文章链接:https://zptheme.com/5063.html
本文作者:子佩·来源:子佩工作室

除非注明,子佩工作室 文章均为原创,转载请以链接形式标明本文地址。

相关推荐

登录后即可发表评论

社交账号登录

全部评论 (70)