- 在WordPress文章顶部或底部添加固定内容是很有必要的,例如公告、广告、通知等等内容
将以下代码粘贴至functions.php 即可
function zm_content_insert( $return = 0 ) {// 插入的内容
$str.= "<div class='same'>";
$str.= "<h4>这是一个h4标题</h4>";
$str.= "<p>示例:<a href='https://jlii.net/' rel='external nofollow' target='_blank'>这是一段内容......</a></p>";
$str.= "</div>";
if ($return) { return $str; } else { echo $str; }
}
function zm_content_filter($content) {
if(!is_feed() && !is_home() && is_singular() && is_main_query()) {
$content .= zm_content_insert(0);// 0 在正文上面
//$content .= zm_content_insert(1);//1 在正文下面
}
return $content;
}
add_filter('the_content','zm_content_filter');