网站首页 >> 建站技术 >> 正文
标题

WordPress玄学优化||后台加速

kmwl520   2024-04-26 16:26:47   17℃   0
内容

今天在群里看见大佬分享的代码,专优化后台,实际体验下来稍微大概也许可能会感知到速度加快吧,应该会吧。。。。

代码

//meta_key字段查询处理
function set_postmeta_choice( $string, $post ) {
    $meta_keys = array();
    foreach(has_meta( $post->ID ) as $meta){
        $meta_keys[] = $meta["meta_key"];
    }
    return $meta_keys;
}
add_filter( 'postmeta_form_keys', 'set_postmeta_choice', 10, 3 );
//wp_dropdown_users()索引问题
add_action('init', 'remove_cpt_author');
function remove_cpt_author() {
remove_post_type_support('page', 'author');
remove_post_type_support('post', 'author');
}

// Add this to your theme's functions.php
// This filter will insure that the wp-image-{IMAGEID} class is added to your 
// image tags, allowing media cloud to work more optimally
add_filter('wp_get_attachment_image_attributes', function($attrs, $attachment, $size) {
    if (!empty($attachment) && isset($attrs['class'])) {
        $attrs['class']  .= ' wp-image-'.$attachment->ID;
    }

    return $attrs;
}, PHP_INT_MAX, 3);

添加到自己启用的主题functions.php中即可!

点评

本文暂无评论 - 欢迎您

请填写验证码