大前端DUX主题WordPress5.x经典编辑器添加pre标签及删除按钮教程

大前端DUX主题WordPress5.x经典编辑器添加pre标签及删除按钮教程,第1张

大前端DUX主题WordPress5.x经典编辑器添加pre标签及删除按钮教程 站长自使用大前端DUX主题以来,很多时间需要用到代码高亮,也试过不少插件。换来换去,个人还是觉得pre好用。但是wordpress经典编辑器的文本里少个代码的快捷方式。网上搜了下有很多不同的方案。选了一个还算凑合用,除了能增加自定义按钮,还可以删除原来的按钮。因为所有代码已经经过测试,所以就直接发代码吧。将以下代码添加到当前使用主题的functions.php,新版大前端DUX主题用户直接放在functions-theme.php //veidc.com添加HTML编辑器pre标签按钮 add_action('after_wp_tiny_mce','add_button_mce'); functionadd_button_mce($mce_settings){ ?> <scripttype="text/javascript"> QTags.addButton('eg_pre','pre','<pre></pre>','','q');//新增按钮 edButtons[120]=null;//删除按钮 </script> <?php }

代码解释

//添加按钮行为添加所需的按钮。

//删除按钮行120是必需的参数。具体参数请参考当前wordpress版本的/wp-includes/js/quicktags.js。

以下是5.2.4版本中的具体参数,大家可以根据自己的需要删除。

edButtons=newqt.TagButton('strong','b','<strong>','</strong>','','','',{ariaLabel:quicktagsL10n.strong,ariaLabelClose:quicktagsL10n.strongClose}); edButtons=newqt.TagButton('em','i','<em>','</em>','','','',{ariaLabel:quicktagsL10n.em,ariaLabelClose:quicktagsL10n.emClose}); edButtons[30]=newqt.LinkButton();//specialcase edButtons[40]=newqt.TagButton('block','b-quote','\n\n<blockquote>','</blockquote>\n\n','','','',{ariaLabel:quicktagsL10n.blockquote,ariaLabelClose:quicktagsL10n.blockquoteClose}); edButtons[50]=newqt.TagButton('del','del','<deldatetime="'+_datetime+'">','</del>','','','',{ariaLabel:quicktagsL10n.del,ariaLabelClose:quicktagsL10n.delClose}); edButtons[60]=newqt.TagButton('ins','ins','<insdatetime="'+_datetime+'">','</ins>','','','',{ariaLabel:quicktagsL10n.ins,ariaLabelClose:quicktagsL10n.insClose}); edButtons[70]=newqt.ImgButton();//specialcase edButtons[80]=newqt.TagButton('ul','ul','<ul>\n','</ul>\n\n','','','',{ariaLabel:quicktagsL10n.ul,ariaLabelClose:quicktagsL10n.ulClose}); edButtons[90]=newqt.TagButton('ol','ol','<ol>\n','</ol>\n\n','','','',{ariaLabel:quicktagsL10n.ol,ariaLabelClose:quicktagsL10n.olClose}); edButtons[100]=newqt.TagButton('li','li','\t<li>','</li>\n','','','',{ariaLabel:quicktagsL10n.li,ariaLabelClose:quicktagsL10n.liClose}); edButtons[110]=newqt.TagButton('code','code','<code>','</code>','','','',{ariaLabel:quicktagsL10n.code,ariaLabelClose:quicktagsL10n.codeClose}); edButtons[120]=newqt.TagButton('more','more','<!--more-->\n\n','','','','',{ariaLabel:quicktagsL10n.more}); edButtons[140]=newqt.CloseButton();

效果显示:

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/743851.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-29
下一篇 2022-04-29

发表评论

登录后才能评论

评论列表(0条)

保存