为wordpress编辑器添加选择中文字体功能

  • 时间:2020-05-20 15:19:20
  • 分类:网络文摘
  • 阅读:139 次

wordpress后台自带 TinyMCE 编辑器,足以应对一般的文字编辑,此外还有众多编辑器增强插件为其赋予了更多功能。下面再介绍一个wordpress技巧,不用插件也能为wordpress编辑器增加选择中文字体功能。

为wordpress编辑器添加选择中文字体功能

一、添加如下代码到wordpress主题的 functions.php 文件中:

  1. function custum_fontfamily($initArray){
  2.    $initArray['font_formats'] = "微软雅黑='微软雅黑';宋体='宋体';黑体='黑体';仿宋='仿宋';楷体='楷体';隶书='隶书';幼圆='幼圆';";
  3.    return $initArray;
  4. }
  5. add_filter('tiny_mce_before_init', 'custum_fontfamily');

二、由于默认的 TinyMCE 编辑器并没有选择字体功能,还需将如下代码也一同加到 functions.php 文件中:

  1. function enable_more_buttons($buttons) {
  2. $buttons[] = 'styleselect';
  3. $buttons[] = 'fontselect';
  4. return $buttons;
  5. }
  6. add_filter("mce_buttons", "enable_more_buttons");

注:此方法适用于WordPress 4.0,之前版本未试。

此外,你还可以试试让WordPress编辑器TinyMCE显示隐藏按钮

推荐阅读:
Bruteforce Algorithm to Find the Unique Positive Integer Whose S  Clone (Deep Copy) Binary Tree With Random Pointer using Hash Map  How to Compute Running Sum of 1d Array using std::partial_sum in  How to Renew the Free SSL Certificates (Nginx Server)?  Design: How to Solve 503 Error of API when Resources are not ava  SteemJs Programming: What Happens on the Steem Blockchain in the  How to Set Up Your On-Call Duty when Your Steem Witness is Missi  Common Mistakes You Can Face With Trying to switch Your Hosting   Recursive Algorithm to Construct Binary Tree from Preorder and P  10 Common Reasons Why Your Blog Doesn’t Make Money 
评论列表
添加评论