[WORDPRESS系列]在主题的 function.php 中给 WordPress 编辑器添加自定义按钮(Quicktags)

参考资料:
http://www.ssdn2007.com/wordpress-add-quicktags-button-in-function-php.html
http://codex.wordpress.org.cn/Quicktags_API

http://yusi123.com/460.html

functions.php 代码
<?php

// 给editor添加更多默认按纽
function enable_more_buttons($buttons) {
	$buttons[] = 'hr';
	$buttons[] = 'fontselect';
	$buttons[] = 'sup';
	$buttons[] = 'del';
	$buttons[] = 'cleanup';
	$buttons[] = 'styleselect';
	 
	// 更多按钮自行添加吧...
	 
	return $buttons;
}
//add_filter("mce_buttons", "enable_more_buttons"); //默认将新添加的按钮追加在工具栏的第一行
//add_filter("mce_buttons_2", "enable_more_buttons");  //添加到工具栏的第二行
add_filter("mce_buttons_3", "enable_more_buttons");  //添加到工具栏的第三行

// 将editor的默认视图改成文本
add_filter('wp_default_editor', create_function('', 'return "html";')); // 默认是add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );

// 编辑器添加默认内容
function insertPreContent($content) {
        if(!is_feed() && !is_home()) {
 			$content.= "这里的预定义内容在编辑器可见";
        }
        return $content;
}
add_filter ('default_content', 'insertPreContent');

// 添加自定义editor 按纽
add_action('admin_print_scripts', 'my_quicktags');
function my_quicktags() {
    wp_enqueue_script(
        'my_quicktags',
        get_stylesheet_directory_uri().'/js/my_quicktags.js',
        array('quicktags')
    );
};
?>

猜你喜欢

转载自lhdst-163-com.iteye.com/blog/2204171