2

WordPress给博客评论框添加一言随机语录

 2 years ago
source link: https://www.huhexian.com/21388.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

WordPress给博客评论框添加一言随机语录

青山 2022-01-0509:31:24评论514字

给博客评论框添加一言随机语录,很早前就在很多博客网站看到了这个每日一句、随机语录等经典语句功能,其实我是非常想要加上这个功能的(功能控~~),但是担心影响访问速度,就一直没开启集成工作。现在发现全是想多了,这个耗不了多少性能,一言 API 的速度还是非常棒的,对加载速度的影响基本可以忽略。

WordPress给博客评论框添加一言随机语录代码-在header、footer等位置添加以下:【子比主题放置在后台自定义】
  1. <script>
  2. $.getJSON("https://api.yum6.cn/yan.php?format=json",function(data){
  3. $("#comment").text(data.text);
  4. $(function(){
  5. $("#comment").click(function() {
  6. $(this).select();
  7. </script>

如果你的评论框 id 不是 comment,则需要修改,首先右键评论框-审查元素-查看 id 或者 class,选其一即可,之后把获取的 id 或者 class 替换到上述代码中的#conment。该 js 需要引入 jquery 库,如果未能正常显示请注意是否成功引入 jquery 库或者是否成功匹配评论框 id 或者 class 值。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK