MarkDown 使用的人现在是越来越多了,对于写作来说 MarkDown 无疑是最好的选择。但 WordPress 并没想加入 MarkDown 语法支持的想法,只能自己动手改一下了。
1.Parsedown Github项目地址: https://github.com/erusev/parsedown/releases/
2.在主题目录下新建一个目录 extend
3.将 Parsedown.php 放到 extend 目录
4.将下面的代码添加到主题目录的 functions.php
function wp_parsedown(){ include_once(get_stylesheet_directory()."/extend/Parsedown.php"); $Parsedown = new Parsedown(); $content = get_the_content(); $content = $Parsedown->text($content); if(is_single() || is_page()){ echo $content; } else{ $content = strip_tags($content); $content = mb_substr($content,0,180,'UTF-8'); echo $content; } } add_action('the_content','wp_parsedown');
最后在写作的时候切换到文本模式就可以是用 MarkDown 语法了。