我已经创建了一个带有文本区域的自定义元框。我如何在这个文本区域中使用降价?我看过一些WP插件,但它们似乎只针对主编辑器。
如何在自定义文本区字段中使用Markdown?
3 个回复
SO网友:shea
您可以下载PHP Markdown 并在保存前使用它解析textarea内容:
if ( ! class_exists( \'Markdown\' ) ) {
require_once( plugin_dir_path(__FILE__) . \'/markdown.php\' );
}
$textarea_contents = Markdown::defaultTransform( $textarea_contents );
SO网友:user2385294
我已安装ACF Custom Field WYSIWYG 和Markdown Extra.
在里面functions.php
, 添加代码:
remove_filter( \'acf_the_content\', \'wpautop\' );
remove_filter( \'acf_the_content\', \'wptexturize\' );
add_filter( \'acf_the_content\', \'Markdown\' );
使用的每个自定义帖子字段acf_the_content
将转换为降价。您也可以使用主要内容:add_filter( \'the_content\', \'Markdown\' );
SO网友:Bordoni
到目前为止,我找到的最好的Markdown解析器是Parsedown
. 类似这样:
if ( ! class_exists( \'Parsedown\' ) ) {
require_once( get_template_directory() . \'/Parsedown.php\' );
}
$parsedown = new Parsedown();
echo $parsedown->text( $content );
如果您正在与客户打交道,这是一种方式,Parsedown几乎是防弹的。结束