原有WordPress编辑文章是不可以给文章调整字体字号的
实现方法
把下面代码加入主题编辑器
//tinymce add bottom function add_more_buttons($buttons) { $buttons[] = 'hr'; $buttons[] = 'del'; $buttons[] = 'sub'; $buttons[] = 'sup'; $buttons[] = 'fontselect'; $buttons[] = 'fontsizeselect'; $buttons[] = 'cleanup'; $buttons[] = 'styleselect'; $buttons[] = 'wp_page'; $buttons[] = 'anchor'; $buttons[] = 'backcolor'; return $buttons; } add_filter("mce_buttons_3", "add_more_buttons"); function customize_text_sizes($initArray){ $initArray['fontsize_formats'] = "12px 13px 14px 15px 16px 17px 18px 19px 20px 21px 22px 23px 24px 25px 26px 27px 28px 29px 30px 32px 34px 36px 38px 42px 44px 46px 48px"; return $initArray; } add_filter('tiny_mce_before_init', 'customize_text_sizes');
想让它有常见中文字体选择追加上下方代码
//中文字体 function custum_fontfamily($initArray){ $initArray['font_formats'] = "微软雅黑='微软雅黑';宋体='宋体';黑体='黑体';仿宋='仿宋';楷体='楷体';隶书='隶书';幼圆='幼圆';ClearSans='clear_sansregular',Helvetica,Arial,sans-serif;ClearSans Medium='clear_sans_mediumregula',Helvetica,Arial,sans-serif;ClearSans Light='clear_sans_lightregular',Helvetica,Arial,sans-serif;ClearSans Thin='clear_sans_thinregular',Helvetica,Arial,sans-serif"; return $initArray; } add_filter('tiny_mce_before_init', 'custum_fontfamily');
成功演示
参考博客
视频教程:https://www.bilibili.com/video/BV1VJ411k7s4
代码博客页面:https://yongwp.com/863.html