WordPress优化

由于有的文章是记录贴,含有相对隐秘的信息,所以要添加部分内容管理员可见,对于资源文件,为了避免太快失效,所以添加评论可见。

添加管理员可见

方法很简单,在当前网站主题下的functions.php文件中添加如下代码:

//加入部分内容隐藏
function login_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '
<span style="color: red;">温馨提示:</span>此处内容仅管理员可见!
'), $atts));
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
 return $content;
 return $notice;
}
add_shortcode('vip', 'login_to_read');

使用时只需要在需要管理员可见的内容前后分别加入【vip】和【/vip】即可(实际使用中要把【】换成[]),如图:

后台代码
管理员前台显示
游客显示

添加评论可见

方法很简单,在当前网站主题下的functions.php文件中添加如下代码:

同时记得把邮箱改成自己的邮箱

/**
* WordPress评论回复可见代码
* https://zhujicankao.com/66279.html
*/
function reply_to_read($atts, $content=null) {     
        extract(shortcode_atts(array("notice" => '<p class="reply-to-read">温馨提示: 此处内容需要<a href="#respond" title="评论本文">评论本文</a>后才能查看.</p>'), $atts));     
        $email = null;     
        $user_ID = (int) wp_get_current_user()->ID;     
        if ($user_ID > 0) {     
            $email = get_userdata($user_ID)->user_email;     
            //对博主直接显示内容     
            $admin_email = "xxx@xxx.com"; //博主Email     
            if ($email == $admin_email) {     
                return $content;     
            }     
        } else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {     
            $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);     
        } else {     
            return $notice;     
        }     
        if (empty($email)) {     
            return $notice;     
        }     
        global $wpdb;     
        $post_id = get_the_ID();     
        $query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";     
        if ($wpdb->get_results($query)) {     
            return do_shortcode($content);     
        } else {     
            return $notice;     
        }     
    }     
      
    add_shortcode('reply', 'reply_to_read');

使用方法和前面的评论可见一样,标签内容为reply

温馨提示: 此处内容需要在文末评论本文并刷新页面后才能查看.

文章按修改时间排序

默认文章是按照发布时间来进行排序的,可以改成按修改时间来进行排序

在函数模版functions.php中添加以下代码:

// sort by modify time
function order_posts_by_mod_date($orderby) 
{   
    if  (is_home() || is_archive() || is_feed()) 
    {     
        $orderby = "post_modified_gmt DESC";   
    }   
    return $orderby; 
} 
add_filter('posts_orderby', 'order_posts_by_mod_date', 999);

bilibili插入视频优化

bilibili视频嵌入WordPress,在b站中点击分享-嵌入代码后,把代码粘贴过来,然后在allowfullscreen=”true”的后面,留1个空格,添加这段代码:

style="width: 100%; height: 500px; max-width: 100%;align:center; padding:20px 0;"

添加雪花效果

style="width: 100%; height: 500px; max-width: 100%;align:center; padding:20px 0;"

添加外部播放器

https://www.ywsj.cf/archives/wang-zhan-zhuang-xiu---gei-ni-de-wang-zhan-tian-jia-mian-fei-yin-le-bo-fang-qi
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇