wordpress纯代码引入Prism高亮并按需加载
纯代码引入Prism高亮,且按需加载,没有代码的文章不输出Prism的css和js。
Function代码
//Prism高亮按需加载,by minirizhi.com
function Prism_Resources($content) {
$pre = "/(pre|<\/pre>)/i";
if(preg_match_all($pre, $content, $matches) && is_single()) {
$content.= '<script type="text/javascript" src="'.site_url().'/content/themes/minirizhi/assets/js/prism.js"></script>
<link rel="stylesheet" id="prismCSS-css" href="'.site_url().'/content/themes/minirizhi/assets/css/prism.css" type="text/css" media="all" />';
}
return $content;
}
add_filter( "the_content", "Prism_Resources");
文章目录
- 上一篇: Wordpress编辑器添加快捷键
- 下一篇: wordpress找回附件上传路径