您的位置:首页»WordPress 教程, 新手入门»  自动为 WordPress 文章、Feed 添加版权等信息

自动为 WordPress 文章、Feed 添加版权等信息

也许,许多同学早已通过修改 WordPress 主题目录下的 single.php 文件以及使用插件的方法为 WordPress 文章、Feed 添加了版权等信息,本文当然不是炒冷饭,而是有了新方法,使用 WordPress 自定义函数以及 add_filter 钩子,自动向 WordPress 内容里添加版权等信息,当然,大家也可以将其替换成广告:)这听起来是不是稍显复杂,其实代码很简单,不信请往下看:
老一套,粘贴以下代码到 functions.php:

1
2
3
4
5
6
7
8
9
10
function insertNote($content) {
        if(!is_feed() && !is_home()) {
                $content.= "<div class='sub'>";
                $content.= "<h4>喜欢这篇文章吗?</h4>";
                $content.= "<p>请订阅本站  <a href='http://eachsite.org/feed'>RSS feed</a> ,站趣-分享建站的乐趣版权所有!</p>";
                $content.= "</div>";
        }
        return $content;
}
add_filter ('the_content', 'insertNote');

怎么样,够简单吧?!至于 CSS 样式,大家根据自身需要定义吧,我就不献丑了。

9个评论

  • Reply 1 篮球博客

    April 17th, 2009 at 11:09

    很好,很强大!

  • Reply 2 拾贰月

    April 18th, 2009 at 11:28

    “喜欢这篇文章吗?”,这句话我怎么听怎么挑逗。

  • Reply 3 welee

    April 18th, 2009 at 20:49

    这对我非常有用,谢了!

  • Reply 4 bolo

    June 27th, 2009 at 13:37

    这样还不如直接修改single.php方便,而且也不灵活

    • Reply 5 辐射鱼

      June 28th, 2009 at 08:02

      囧,这咋不方便灵活了哦?而且你放single.php里,feed里不会显示

  • Reply 6 BestDong

    September 24th, 2009 at 15:56

    学习了,收藏备用.

  • Reply 7 对讲机

    May 29th, 2010 at 14:31

    研究研究,,