之前也有写过在文章底部默认添加版权信息,但是发现不完美的地方就是不能统一修改内容,如果有错别字或者内容需要修改只能到数据库里面使用SQL语言修改特别麻烦,所以现在想完善一下代码,我们可以这样为wordpress发布文章时默认在底部添加版权信息。
打开functions.php文件添加以下代码:
[code]function xgllseo_content($more_link_text = null, $stripteaser = 0) {
$content = get_the_content($more_link_text, $stripteaser);
$content.= “<pre>转载请注明来自:<a href=’https://sdeno.com’>wordpress建站教程|wordpress主题制作|wordpress模板</a>,”;
$content.= “<br>本文地址:<a href='”.get_permalink().”‘ title='”.get_the_title($post_id).”‘>http://wwww.xgllseo.com/”.get_the_title($post_id).”/</a>”;
$content.= “\n转载请注明出处和链接!</pre>”;
$content = apply_filters(‘the_content’, $content);
$content = str_replace(‘]]>’, ‘]]>’, $content);
echo $content;
}[/code]
以上是定义了一个函数现在我们要调用此函数,在你发布文章的页面替换添加以下代码:
[code]<div class=”entry-content”>
<?php xgllseo_content(); ?>
<?php wp_link_pages( array( ‘before’ => ‘<div class=”page-link”>’ . __( ‘Pages:’, ‘twentyeleven’ ), ‘after’ => ‘</div>’ ) ); ?>
</div><!– .entry-content –>[/code]
以后每当你发布一篇文章底部就默认添加版权信息了。