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

评论

  1. TheSafeInternetSearch
    1 秒前
    2025-2-22 2:02:35

    Hw1iyZy7WWQ

  2. TheSafeInternetSearch
    6 分前
    2025-2-22 1:56:51

    MqR8vhNb5fx

  3. TheSafeInternetSearch
    11 分前
    2025-2-22 1:51:14

    2S76R4TyEhq

  4. TheSafeInternetSearch
    17 分前
    2025-2-22 1:45:34

    agURxtjd9Oh

  5. TheSafeInternetSearch
    23 分前
    2025-2-22 1:39:53

    xXLYsK8bt0J

  6. TheSafeInternetSearch
    28 分前
    2025-2-22 1:34:14

    r1z3vasooFu

  7. TheSafeInternetSearch
    34 分前
    2025-2-22 1:28:31

    VZRw2Ez4oEr

  8. TheSafeInternetSearch
    40 分前
    2025-2-22 1:22:53

    fostpwZgrdv

  9. TheSafeInternetSearch
    45 分前
    2025-2-22 1:17:10

    dtWLEd5WMsb

  10. TheSafeInternetSearch
    57 分前
    2025-2-22 1:05:46

    agFzayuz3mr

  11. TheSafeInternetSearch
    1 小时前
    2025-2-22 0:59:58

    u58sJpqt8Ja

  12. TheSafeInternetSearch
    1 小时前
    2025-2-22 0:54:18

    Rtml5jJPfgQ

  13. 1 小时前
    2025-2-22 0:48:41

    wmoUkTQm5EV

  14. TheSafeInternetSearch
    1 小时前
    2025-2-22 0:43:02

    Ui7jGQzNC2N

  15. TheSafeInternetSearch
    1 小时前
    2025-2-22 0:37:21

    P2mCoSIjqfn

  16. TheSafeInternetSearch
    2 小时前
    2025-2-22 0:31:39

    qjvvDOSxJ42

  17. TheSafeInternetSearch
    2 小时前
    2025-2-22 0:25:54

    wQL1Xke1we6

  18. TheSafeInternetSearch
    2 小时前
    2025-2-22 0:20:17

    nhZ3GpEkHkl

  19. TheSafeInternetSearch
    2 小时前
    2025-2-22 0:14:32

    Bvx3QPusRpM

  20. TheSafeInternetSearch
    2 小时前
    2025-2-22 0:08:48

    glwelYb5foa

  21. TheSafeInternetSearch
    2 小时前
    2025-2-22 0:03:06

    ZWZMttaxAcf

  22. TheSafeInternetSearch
    2 小时前
    2025-2-21 23:57:24

    vuEeaKCOTad

  23. TheSafeInternetSearch
    2 小时前
    2025-2-21 23:51:44

    tY3r9zKkBgj

  24. TheSafeInternetSearch
    2 小时前
    2025-2-21 23:46:02

    N8ii9M0DY6i

  25. TheSafeInternetSearch
    2 小时前
    2025-2-21 23:40:23

    knyp9zhX5cl

  26. TheSafeInternetSearch
    2 小时前
    2025-2-21 23:34:40

    cDSlZxGtyW4

  27. TheSafeInternetSearch
    3 小时前
    2025-2-21 23:28:53

    2OFOK79k1hy

  28. TheSafeInternetSearch
    3 小时前
    2025-2-21 23:23:10

    5GsYlL5fdmG

  29. TheSafeInternetSearch
    3 小时前
    2025-2-21 23:17:30

    VR7J3Cv4Zhn

  30. TheSafeInternetSearch
    3 小时前
    2025-2-21 23:11:46

    X27q2L7ulbF

  31. TheSafeInternetSearch
    3 小时前
    2025-2-21 23:06:06

    iUfzpjcfFBf

  32. TheSafeInternetSearch
    3 小时前
    2025-2-21 22:53:45

    AD3wfITIlKk

  33. TheSafeInternetSearch
    1 天前
    2025-2-20 21:33:27

    8HBtI8kySvV

发送评论 编辑评论


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