当前位置:网站首页>Code implementation WordPress writing articles can adjust font size

Code implementation WordPress writing articles can adjust font size

2022-06-09 14:07:00 ZDB

The original WordPress Editing an article is not allowed to adjust the font size of the article

Implementation method

Add the following code to the theme editor
 Insert picture description here

 //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');

If you want it to have common Chinese fonts, add the upper and lower codes

    // Chinese Fonts 
function custum_fontfamily($initArray){
    
$initArray['font_formats'] = " Microsoft YaHei =' Microsoft YaHei '; Song style =' Song style '; In black =' In black '; Imitation song =' Imitation song '; Regular script =' Regular script '; Official script =' Official script '; Juvenility =' Juvenility ';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');

Successful demonstration

 Insert picture description here

Reference blog

Video tutorial :https://www.bilibili.com/video/BV1VJ411k7s4
Code blog page :https://yongwp.com/863.html

原网站

版权声明
本文为[ZDB]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091255457400.html