插件介紹
Pure-Highlightjs一個基于Highlightjs實現的WordPress代碼高亮插件,此次分享的是仿mac風格代碼塊,支持代碼一鍵全選、復制功能,滿足用戶所需,支持 N 多種語言高亮,還提供多種主題兼容適配。支持在 WordPress 可視化編輯模式下插入代碼。
插件優勢
Pure Highlightjs 這個插件經過精簡目前只有0.5 MB,非常小巧,基本不會給網站加載帶來多余的負載。
插件演示
//WordPress 文章關鍵詞自動內鏈
function tag_sort($a, $b){
if ( $a->name == $b->name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
function tag_link($content){
$match_num_from = 1;//一個標簽少于幾次不鏈接
$match_num_to = 1;//一個標簽最多鏈接幾次
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, "tag_sort");
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
//鏈接代碼
$cleankeyword = stripslashes($keyword);
$url = "".addcslashes($cleankeyword, '$')."";
$limit = rand($match_num_from,$match_num_to);
//不鏈接代碼
$content = preg_replace( '|(<a[^>]+>)(.*)<pre.*?>('.$ex_word.')(.*)(</pre.*?></a[^>]*>)|U'.$case, '$1$2%&&&&&%$4$5', $content);
$content = preg_replace( '|(<img)(.*?)('.$ex_word.')(.*?)(>)|U'.$case, '$1$2%&&&&&%$4$5', $content);</img)(.*?)('.$ex_word.')(.*?)(>
$cleankeyword = preg_quote($cleankeyword,''');
$regEx = ''(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?))'s' . $case;
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( '%&&&&&%', stripslashes($ex_word), $content);
}
}
return $content;
}
add_filter('the_content','tag_link',1);
安裝說明
1、安裝
進入 WordPress 后臺管理頁面, 插件 > 安裝插件 > 上傳插件 ,上傳剛才下載的 ZIP 文件,然后安裝。
或者解壓安裝包,上傳到插件目錄 /wp-content/plugins/
2、啟用
安裝完畢后,在已經安裝的插件里啟用 “Pure Highlightjs”
使用說明
1、編輯器可視化插入代碼
2、Pure Highlightjs 后臺進入設置選項
3、Pure Highlightjs 選擇代碼高亮樣式“Coy”
聲明:本站所有資源由用戶發布分享以及互聯網轉載,只作為宣傳購買原版的參考,版權爭議與本站無關;如果你有什么不錯的資源,也可以提供給本站免費幫你發布宣傳;本站不對任何資源負法律責任以及索取相關費用,您若發現本站侵犯了你的版權利益,請聯系本站刪除處理!謝謝!