WordPress插件开发: 给每篇文章后面添加版权信息

给每篇文章后面添加版权信息的方法。如下面代码:

<?php
/**
 * @package heronk_copyright
 * @version 1.0
 */
/*
Plugin Name: heronk_copyright
Plugin URI: https://www.oddbacn/40.html
Description: 给每篇文章后面添加版权信息
Author: heronk
Version: 1.0
Author URI: https://www.oddbacn
*/
/*
  Copyright 2023  作者名 heronk (email : 27586455@qq.com)

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

// 当加载文章内容的时候,执行添加版权信息的方法
add_action('the_content', 'add_copyright_info');

/**
 * [add_copyright_info 输出内容后连上要显示的版权信息,简单设置增加版权信息的内容的样式]
 * @param [type] $content [string]
 */
function add_copyright_info ($content){
    $content .= '<div style="clear:both; border-top:1px dashed #e0e0e0; padding:10px 0 10px 0; font-size:12px;">版权所有©转载必须以链接形式注明作者和原始出处:<a href="'.get_bloginfo("home").'" title="点击去首页">'.get_bloginfo("name").'</a> » <a title="本文地址" href="'.get_permalink().'">'.get_the_title().'</a></div>' ;
    return $content;
}
?>

简单插件的文件也可以跟随主题一并启用,在 /wp-content/themes/主题文件夹/functions.php 文件最后加入如下代码:

function add_copyright_info ($content){
    $content .= '<div style="clear:both; border-top:1px dashed #e0e0e0; padding:10px 0 10px 0; font-size:12px;">版权所有©转载必须以链接形式注明作者和原始出处:<a href="'.get_bloginfo("home").'" title="点击去首页">'.get_bloginfo("name").'</a> » <a title="本文地址" href="'.get_permalink().'">'.get_the_title().'</a></div>' ;
    return $content;
}

 

本文采用「CC BY-SA 4.0 CN」协议转载自互联网、仅供学习交流,内容版权归原作者所有,如涉作品、版权和其他问题请留言处理。

给TA打赏
共{{data.count}}人
人已打赏
玩站

WordPress 插件开发-插件基础

2023-2-23 12:57:35

玩站

WordPress插件开发 - 添加菜单

2023-2-23 17:06:01

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧