大前端DUX主題WordPress5.x經(jīng)典編輯器添加pre標(biāo)簽及刪除按鈕教程

站長自使用大前端DUX主題以來,很多時(shí)間需要用到代碼高亮,也試過不少插件。換來換去,個(gè)人還是覺得pre好用。但是wordpress經(jīng)典編輯器的文本里少個(gè)代碼的快捷方式。網(wǎng)上搜了下有很多不同的方案。選了一個(gè)還算湊合用,除了能增加自定義按鈕,還可以刪除原來的按鈕。因?yàn)樗写a已經(jīng)經(jīng)過測試,所以就直接發(fā)代碼吧。將以下代碼添加到當(dāng)前使用主題的functions.php,新版大前端DUX主題用戶直接放在functions-theme.php

//veidc.com 添加HTML編輯器pre標(biāo)簽按鈕
add_action('after_wp_tiny_mce', 'add_button_mce');
function add_button_mce($mce_settings) {
?>
<script type="text/javascript">
QTags.addButton( 'eg_pre', 'pre', '<pre></pre>', '', 'q' );  //新增按鈕
edButtons[120]=null;  //刪除按鈕
</script>
<?php
}

代碼解釋

//新增按鈕行為新增需要的按鈕。

//刪除按鈕行120為所需的參數(shù),具體參數(shù)可以查看當(dāng)前wordpress版本的/wp-includes/js/quicktags.js

這里展示5.2.4版本里的具體參數(shù),按自己需求刪除即可。

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

效果展示:

贊(0)
版權(quán)聲明:本文采用知識共享 署名4.0國際許可協(xié)議 [BY-NC-SA] 進(jìn)行授權(quán), 轉(zhuǎn)載請注明出處。
文章名稱:《大前端DUX主題WordPress5.x經(jīng)典編輯器添加pre標(biāo)簽及刪除按鈕教程》
文章鏈接:http://www.lrracing.com/11159.html
【聲明】:國外主機(jī)測評僅分享信息,不參與任何交易,也非中介,所有內(nèi)容僅代表個(gè)人觀點(diǎn),均不作直接、間接、法定、約定的保證,讀者購買風(fēng)險(xiǎn)自擔(dān)。一旦您訪問國外主機(jī)測評,即表示您已經(jīng)知曉并接受了此聲明通告。
【關(guān)于安全】:任何 IDC商家都有倒閉和跑路的可能,備份永遠(yuǎn)是最佳選擇,服務(wù)器也是機(jī)器,不勤備份是對自己極不負(fù)責(zé)的表現(xiàn),請保持良好的備份習(xí)慣。