更改wp后台默认投稿名称

function revcon_change_post_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'News';
    $submenu['edit.php'][5][0] = 'News';
    $submenu['edit.php'][10][0] = 'Add News';
    $submenu['edit.php'][16][0] = 'News Tags';
}
function revcon_change_post_object() {
    global $wp_post_types;
    $labels = &$wp_post_types['post']->labels;
    $labels->name = 'News';
    $labels->singular_name = 'News';
    $labels->add_new = 'Add News';
    $labels->add_new_item = 'Add News';
    $labels->edit_item = 'Edit News';
    $labels->new_item = 'News';
    $labels->view_item = 'View News';
    $labels->search_items = 'Search News';
    $labels->not_found = 'No News found';
    $labels->not_found_in_trash = 'No News found in Trash';
    $labels->all_items = 'All News';
    $labels->menu_name = 'News';
    $labels->name_admin_bar = 'News';
}
 
add_action( 'admin_menu', 'revcon_change_post_label' );
add_action( 'init', 'revcon_change_post_object' );

社交分享按钮

<ul class="socialList">
            <li><a href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>" target="_blank"
                    title="Facebook">facebook</a></li>
            <li><a href="http://twitter.com/intent/tweet?text=<?php the_permalink(); ?>" target="_blank"
                    title="Twitter">twitter</a></li>
            <li><a href="http://b.hatena.ne.jp/add?mode=confirm&url=<?php the_permalink(); ?>" target="_blank" title="はてブ">b!</a>
            </li>
            <li><a href="http://line.naver.jp/R/msg/text/?<?php the_permalink(); ?>" target="_blank" title="LINE">line</a>
            </li>
        </ul>

wp将自定义分类checkBox更改为radio

wp_terms_checklist() ;

function term_radio_checklist( $args ) {
    if ( ! empty( $args['taxonomy'] ) && $args['taxonomy'] === 'other_tag' /* <== Change to your required taxonomy */ ) {
        if ( empty( $args['walker'] ) || is_a( $args['walker'], 'Walker' ) ) { // Don't override 3rd party walkers.
            if ( ! class_exists( 'Radio_Checklist' ) ) {
                class Radio_Checklist extends Walker_Category_Checklist {
                    public function walk( $elements, $max_depth, ...$args ) {
                        $output = parent::walk( $elements, $max_depth, ...$args );
                        $output = str_replace(
                            array( 'type="checkbox"', "type='checkbox'" ),
                            array( 'type="radio"', "type='radio'" ),
                            $output
                        );

                        return $output;
                    }
                }
            }

            $args['walker'] = new Radio_Checklist;
        }
    }
    return $args;
}
add_filter( 'wp_terms_checklist_args', 'term_radio_checklist' );

规定时间内发布的文章显示new标签

<?php
$pub_date = strtotime(get_the_date("Y-m-d H:i:s")) + 30*24*60*60;
$cur_date = strtotime(date("Y-m-d H:i:s")); ?>
<span class="time <?php if($pub_date >= $cur_date ){ echo 'shownew';}?>"><?php the_time('Y.m.d'); ?></span>

slick 同步幻灯片 自动播放的方法

$('.slider-for').slick({
    slidesToShow: 1,
    slidesToScroll: 1,
    arrows: false,
    fade: true,        
    autoplay:true,
    //trigger after the slide appears
    // i is current slide index
    onAfterChange:function(slickSlider,i){
         //remove all active class
         $('.slider-nav .slick-slide').removeClass('slick-active');
         //set active class for current slide
         $('.slider-nav .slick-slide').eq(i).addClass('slick-active');         
     }

});


//set active class to first slide
$('.slider-nav .slick-slide').eq(0).addClass('slick-active');

Ajax

https://api.jquery.com/jQuery.ajax/

/*enqueue localize*/
wp_enqueue_script('script-js', get_template_directory_uri() . '/js/script.js', array('jquery'), '1.0.0', false);
    //ajax
    wp_localize_script( 'script-js', 'frontend_ajax_object',
        array( 
            'home' => get_option('home'),
        )
    );
/*script pkb*/
var $obj_id = $('.single-salon-collection .num').attr('id');
$.ajax({
url: frontend_ajax_object.home + '/salon-collection/',
context: document.body
}).done(function(data) {
var $number = $(data).find('#' + $obj_id).find('.order').html();
$('.single-salon-collection .num').html($number);
});

Mange users columns

Add columns:

function new_modify_user_table( $column ) {
    $column['phone'] = 'Phone';
    $column['xyz'] = 'XYZ';
    return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );

function new_modify_user_table_row( $val, $column_name, $user_id ) {
    switch ($column_name) {
        case 'phone' :
            return get_the_author_meta( 'phone', $user_id );
        case 'xyz' :
            return '';
        default:
    }
    return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );

Remove columns:

$c = array( ‘cb’ => ‘<input type=”checkbox” />’, ‘username’ => __( ‘Username’ ), ‘name’ => __( ‘Name’ ), ’email’ => __( ‘E-mail’ ), ‘role’ => __( ‘Role’ ), ‘posts’ => __( ‘Posts’ ) );

If for example you need to remove E-mail column you should unset a column with ’email’ ID. Let’s go to the final step:

add_filter('manage_users_columns','remove_users_columns');
function remove_users_columns($column_headers) {
    if (current_user_can('moderator')) {
      unset($column_headers['email']);
    }
 
    return $column_headers;
}

We use manage_users_columns filter to achieve this purpose. This code removes ‘E-mail’ folder for users with ‘moderator’ role. Replace it with your own one.
In order to remove other column replace ’email’ column ID to that column ID: role, posts, etc.

Other variant for the list of roles:

add_filter('manage_users_columns','remove_users_columns');
function remove_users_columns($column_headers) {
    $roles = array('moderator', 'users-list-viewer');
    foreach($roles as $role) {
        if (current_user_can($role)) {
            unset($column_headers['email']);
            break;
        }
    }
 
    return $column_headers;
}

Another variant for the list of users ID:

add_filter('manage_users_columns','remove_users_columns');
function remove_users_columns($column_headers) {
    global $current_user;
 
    $users = array(27, 70530, 70531, 70532);
 
    if (in_array($current_user->ID, $users)) {
        unset($column_headers['email']);
    }    
 
    return $column_headers;
}