欢迎来访~

wordpress编辑器自定义字体字号

wordpress编辑器自定义字体,wordpress编辑器修改字号,wordpress编辑器自定义文字颜色

使用方法

将所需要的代码添加到主题的functions.php中即可。

代码

自定义字体

//编辑器自定义字体
function customize_font_family($initArray){ 
  $initArray['font_formats'] = "Arial='Arial',Helvetica,Arial,sans-serif;Times New Roman='Times New Roman',Helvetica,Arial,sans-serif;宋体='宋体',Helvetica,Arial,sans-serif;仿宋='仿宋',Helvetica,Arial,sans-serif;仿宋GB2312='仿宋GB2312',Helvetica,Arial,sans-serif;楷体='楷体',Helvetica,Arial,sans-serif;黑体='黑体',Helvetica,Arial,sans-serif;华文新魏='华文新魏',Helvetica,Arial,sans-serif;隶书='隶书',Helvetica,Arial,sans-serif; 微软雅黑='微软雅黑',Helvetica,Arial,sans-serif";
  return $initArray;
}
add_filter('tiny_mce_before_init', 'customize_font_family');

 

修改字号

//编辑器修改字号
function customize_text_sizes($initArray){
   $initArray['fontsize_formats'] = "8px 10px 12px 14px 15px 16px 18px 20px 24px 28px 32px 48px";
   return $initArray;
}
add_filter('tiny_mce_before_init', 'customize_text_sizes');

 

自定义文字颜色

//编辑器自定义文字颜色
function customize_text_color($initArray){
   $default_colours = '
    "000000", "Black",        "993300", "Burnt orange", "333300", "Dark olive",   "003300", "Dark green",   "003366", "Dark azure",   "000080", "Navy Blue",      "333399", "Indigo",       "333333", "Very dark gray",
    "800000", "Maroon",       "FF6600", "Orange",       "808000", "Olive",        "008000", "Green",        "008080", "Teal",         "0000FF", "Blue",           "666699", "Grayish blue", "808080", "Gray",
    "FF0000", "Red",          "FF9900", "Amber",        "99CC00", "Yellow green", "339966", "Sea green",    "33CCCC", "Turquoise",    "3366FF", "Royal blue",     "800080", "Purple",       "999999", "Medium gray",
    "FF00FF", "Magenta",      "FFCC00", "Gold",         "FFFF00", "Yellow",       "00FF00", "Lime",         "00FFFF", "Aqua",         "00CCFF", "Sky blue",       "993366", "Brown",        "C0C0C0", "Silver",
    "FF99CC", "Pink",         "FFCC99", "Peach",        "FFFF99", "Light yellow", "CCFFCC", "Pale green",   "CCFFFF", "Pale cyan",    "99CCFF", "Light sky blue", "CC99FF", "Plum",         "FFFFFF", "White"
';
$custom_colours = '
    "898989", "#898989", "666565", "#666565"
';
$initArray['textcolor_map'] = '['.$custom_colours.','.$default_colours.']'; // build colour grid default+custom colors
$initArray['textcolor_rows'] = 6; // enable 6th row for custom colours in grid
 
   return $initArray;
}
add_filter('tiny_mce_before_init', 'customize_text_color');
 

个人觉得自定义文字颜色就没必要了,自定义字体和字号还是挺实用的。

我喜欢用15px的字号,也就是11pt,默认wordpress编辑器没有11pt这个字号,只有10pt,12pt…. 比较坑。所以才网上搜了一番,整理出了这些,供参考。

 
-The End-
 
赞(0)
可附来源转载:一只北极熊 » wordpress编辑器自定义字体字号

富强、民主、文明、和谐、自由、平等、公正、法治、爱国、敬业、诚信、友善