wordpress添加版权年份信息

WordPress给网站底部添加版权信息,类似于 @2012-2015 WordPress巴士 版权所有的信息,难点在于获取开始时间的2012年。本文将分享的一种是利用作者注册时间结合现在时间来计算的代码。

将以下代码粘贴到主题的function.php的底部:

//显示网站运营版权时间
//https://wp.qdkfweb.cn/auto-copyright/
function wpbars_auto_copyright() {
global $wpdb;
$first = $wpdb->get_results("
SELECT user_registered
FROM $wpdb->users
ORDER BY ID ASC
LIMIT 0,1
");
$output = '';
$current = date(Y) ;
if($first) {
$first=date(Y,strtotime($first[0]->user_registered));
$copyright = "© " . $first;
if($first != $current) {
$copyright .= '-' .$current;
}
$output = $copyright;
}
echo $output;
}

调用方式

在主题的footer.php的版权位置添加如下代码:

<?php wpbars_auto_copyright(); ?>

声明: 未经本站许可,谢绝转载!

0 个主题帖 其中:热心观众:0 个, 管理员:0 个

抱歉,评论被关闭