wordpress技巧

修改主题文件夹下的functions.php文件(如wp-content/themes/twentyfourteen/functions.php)

获取第一张缩略图:

function get_post_thumbnail_url($post_id){

//        $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;

//        $thumbnail_id = get_post_thumbnail_id($post->ID);

//        if($thumbnail_id ){

//                $thumb = wp_get_attachment_image_src($thumbnail_id, 'thumbnail');

//                return $thumb[0];

//        }else{

//                return false;

//        }

    

    $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );

    $src = wp_get_attachment_image_src( $thumbnail_id, 'post-thumbnail' );

    return $src[0];

}

开启隐藏的编辑按钮:

//开启更多编辑器按键

function enable_more_buttons($buttons) {   

    //$buttons[] = 'hr';

    //$buttons[] = 'sub';

    //$buttons[] = 'sup';

    $buttons[] = 'fontselect';

    $buttons[] = 'fontsizeselect';

    //$buttons[] = 'styleselect';

    $buttons[] = 'backcolor';

    //$buttons[] = 'cleanup';

    //$buttons[] = 'anchor';

    //$buttons[] = 'image';

    $buttons[] = 'wp_page';

    return $buttons;   

}

add_filter("mce_buttons_3", "enable_more_buttons");//添加到工具栏的第三行

开启更多字体设置:

function custum_fontfamily($initArray){

   $initArray['font_formats'] = "宋体='宋体';黑体='黑体';仿宋='仿宋';楷体='楷体';微软雅黑='微软雅黑';Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times;Verdana=verdana,geneva;";

   $initArray['fontsize_formats'] = "10px 12px 14px 16px 18px 20px 22px 24px 26px 28px 30px 36px 40px";

   return $initArray;

}

add_filter('tiny_mce_before_init', 'custum_fontfamily');

添加编辑器按钮(添加<center>按钮)

// add more buttons to the html editor
function appthemes_add_quicktags() {
    if (wp_script_is('quicktags')){
		$script = <<<EOT
<script type="text/javascript">
QTags.addButton( 'eg_center', 'center', '<center>', '</center>', 'c', 'Center tag', 111 );
//QTags.addButton( 'eg_paragraph', 'p', '<p>', '</p>', 'p', 'Paragraph tag', 1 );
//QTags.addButton( 'eg_hr', 'hr', '<hr />', '', 'h', 'Horizontal rule line', 201 );
//QTags.addButton( 'eg_pre', 'pre', '<pre lang="php">', '</pre>', 'q', 'Preformatted text tag', 111 );
//</script>
EOT;
		echo $script;
    }
}
add_action( 'admin_print_footer_scripts', 'appthemes_add_quicktags' );

提升JPEG图片质量:

//improve jpeg quality

add_filter( 'jpeg_quality', create_function( '', 'return 100;' ) );

删除评论表单字段

add_filter('comment_form_default_fields', 'mytheme_remove_url');
 
function mytheme_remove_url($arg) {
    $arg['url'] = '';
    return $arg;
}

 

Post Navigation