浮萍漂泊本无根
天涯游子君莫问

给wordpress默认编辑器增强添加h1h2h3等常用标签

前面小编讲过怎样增强wordpress默认编辑器,为怎样修改wordpess编辑器中文章内容字体的字号大小今天给大家讲下怎样给wp编辑器添加h1h2h3常用标签,其实方法都是一样的,只是改变了标签的类型说明而已。

wordpress增加h1h2自定义标签办法:找到wp主题的functions.php文件,路径为:/home/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>n", "n</pre>n" );
</script>
<?php
}

//pre防html转义代码
 // 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>(.*?)<\/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) 打赏
未经允许不得转载:主题秀 » 给wordpress默认编辑器增强添加h1h2h3等常用标签

评论 抢沙发

评论前必须登录!

 

更好的WordPress主题

支持快讯、专题、百度收录推送、人机验证、多级分类筛选器,适用于垂直站点、科技博客、个人站,扁平化设计、简洁白色、超多功能配置、会员中心、直达链接、文章图片弹窗、自动缩略图等...

联系我们联系我们

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册