
通常来说中文与英文、中文和数字之间加上空格的排版会更加好看,但是如果让我们在编辑文章的时候人工添加,感觉非常繁琐和让人厌烦,所以今天就来跟大家介绍一下WordPress如何实现中英文数字之间自动加空格的排版技巧。
第一步:html标签中加入han-la类
2、在主题的 header.php 的 html 标签中添加class=”han-la”,如找到以下代码:
<html lang="zh-CN">
修改为:
<html lang="zh-CN" class="han-la">
第二步:引入js文件
在jquery文件后面引入text-autospace.min.js或text-autospace.js
JS相关文件下载
/**
* WordPress实现中英文数字之间自动加空格排版
* http://www.vlwx.com/117.html
*/
function yyob_styles_scripts() {
//全局加载js脚本
wp_enqueue_script( 'han-la-js', get_template_directory_uri() . '/includes/js/text-autospace.min.js', array( 'jquery' ), '', true );
}
add_action( 'wp_enqueue_scripts', 'yyob_styles_scripts' );
注意修改代码中js文件的引用路径哦~
第三步:添加CSS代码
将以下代码加入你的style.css文件中。
/* WordPress实现中英文数字之间自动加空格排版 */
html.han-la hanla:after {
content: " ";
display: inline;
font-family: Arial;
font-size: 0.89em;
}
html.han-la code hanla,
html.han-la pre hanla,
html.han-la kbd hanla,
html.han-la samp hanla {
display: none;
}
html.han-la ol > hanla,
html.han-la ul > hanla {
display: none;
}
友情提示:因为添加了JS和CSS文件,故要记得清空主题插件缓存、CDN缓存及浏览器缓存哦~