[WordPress教程] wordpress编辑器增加pre自定义标签 -静鱼客栈

2021-09-26 0 552

wordpress输入带格式的代码时,每次都需要手动输入pre标签很不方便。如何能够像编辑器带的b标签一样,点一下就自动输入,wordpress增加自定义标签办法修改主题的functions.php文件,路径为:

/网站路径/wp-content/themes/主题文件夹/functions.php,


//添加HTML编辑器自定义快捷标签按钮
add_action('after_wp_tiny_mce', 'add_button_mce');
function add_button_mce($mce_settings) {
?>
<script type="text/javascript">
    QTags.addButton( 'hr', 'hr', "\n<hr />\n", "" );
    QTags.addButton( 'h1', 'h1', "\n<h1>", "</h1>\n" );
    QTags.addButton( 'h2', 'h2', "\n<h2>", "</h2>\n" );
    QTags.addButton( 'h3', 'h3', "\n<h3>", "</h3>\n" );
    QTags.addButton( 'pre', 'pre', "\n<pre class="line-numbers language-php"><code class="language-php">\n", "\n\n" );

wordpre pre标签内的html代码转义,想在wordpress 文章中插入代码,例如php的


// convert htmlentity for pre tag
add_filter('the_content', 'htmlspecialchars_pre', 12);
add_filter('get_comment_text', 'htmlspecialchars_pre');
function htmlspecialchars_pre ($content) {
         return preg_replace_callback ("/<pre class="line-numbers language-php"><code class="language-php">(.*?)<\/pre>/si", create_function('$matches','return "<"."pre".">" . htmls_pecial_chars($matches[1]) ."<"."/pre>";'),$content);
}
function htmls_pecial_chars($content=''){
    $content = str_replace("<","<",$content);
    $content = str_replace(">",">",$content);
    $content = str_replace("&","&",$content);
    $content = str_replace('"','"',$content);
    $content = str_replace("'","'",$content);
    $content = str_replace(" "," ",$content);
     return $content;
}

 

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝/QQ扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

1. 本站所有资源来源于用户上传和网络,因此不包含技术服务请大家谅解!如有侵权请邮件联系客服!305582964@qq.com
2. 本站不保证所提供下载的资源的准确性、安全性和完整性,资源仅供下载学习之用!如有链接无法下载、失效或广告,请联系客服处理,有奖励!
3. 您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容资源!如用于商业或者非法用途,与本站无关,一切后果请用户自负!
4. 如果您也有好的资源或教程,您可以投稿发布,成功分享后有U点奖励和额外收入!

静鱼客栈 学习中心 [WordPress教程] wordpress编辑器增加pre自定义标签 -静鱼客栈 https://www.52jyu.cn/9375.html

静鱼客栈的帅逼站长~

常见问题
  • 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP贵宾介绍。
查看详情
  • 最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器没有下载完整造成的,可以重新进行下载即可~
查看详情

相关文章

发表评论
暂无评论
静鱼客栈-站长

为您解决烦忧 - 专业服务 看到消息会进行回复