方法1,纯代码的方式添加,适合不喜欢用插件的同学:
//1,允许在WordPress后台media媒体库上传字体,将下面代码添加到主题的functions.php中 类 FJJ_SUPPORT_TTF_MEDIA{ 公共函数 __construct(){ add_filter('upload_mimes', array($this,'fjj_upload_media_mimes')); add_filter( 'wp_check_filetype_and_ext', array($this,'fjj_check_types'), 10, 4 ); } function fjj_upload_media_mimes($fjj_mimes) { $fjj_mimes['ttf'] = 'application/x-font-ttf'; $fjj_mimes['otf'] = 'application/x-font-otf'; $fjj_mimes['eot'] = 'application/x-font-eot'; $fjj_mimes['woff'] = 'application/x-font-woff'; $fjj_mimes['woff2'] = 'application/x-font-woff2'; 返回 $fjj_mimes; } function fjj_check_types( $checked, $file, $filename, $mimes ) { 如果 ( ! $checked['type'] ) { $check_filetype = wp_check_filetype( $filename, $mimes ); $ext = $check_filetype['ext']; $type = $check_filetype['类型']; $proper_filename = $filename; $checked = compact( 'ext','type','proper_filename' ); } 返回 $checked; } } new FJJ_SUPPORT_TTF_MEDIA(); //2,将下载好的字体,后缀是ttf格式,上传到 WordPress 后台media 媒体库,上传成功后,获取到字体的文件路径,//类似:。 //类似:http://127.0.0.1/wp-content/uploads/2023/09/Super-Dream.ttf //3,将下面代码添加到主题的style.css: @font-face { font-family: 'SuperDream'; /* 字体名称 */ src: url('http://127.0.0.1/wp-content/uploads/2023/09/Super-Dream.ttf') format('truetype'); /* 字体文件的路径和格式 */ font-weight: normal; /* 字体的重量 */ font-style: normal; /* 字体的样式 */ } //4,在WordPress前端调用新字体: //4,在WordPress前端调用新字体 h1.product_title.entry-title { font-family:SuperDream; }
方法2,直接使用插件,跳过方法1的1,2,3步骤:https://wordpress.org/plugins/custom-fonts/
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)