
Jos Hoàng Tiên tao nghe nói mày đang học bí kíp luyện rồng! Chia sẻ cho tao ít đi.

Được! Một số bí kíp mà tao tìm được trong WordPress đây.
Xóa thanh điều khiển Admin
PHP
add_filter('show_admin_bar', '__return_false')
Nén code tăng tốc cho trang
PHP
function sanitize_output($buffer) { search=array(′/[§]+/s′,′/[§]+\</s′,′/(\s)+/s′);replace = array( '>', '<', '\\1' ); buffer=pregreplace(search, replace,buffer); return $buffer; } ob_start("sanitize_output");
Đếm số ký tự trong bài viết
PHP
function post_word_count() { global post;words = str_word_count(strip_tags(get_post_field('post_content', get_the_ID()))); time=words/250; if ( $time < 1) { echo 1; } else { echo round($time, 1, PHP_ROUND_HALF_UP); } }
Đếm số ký tự trong bài viết
PHP
function post_word_count() { global post;words = str_word_count(strip_tags(get_post_field('post_content', get_the_ID()))); time=words/250; if ( $time < 1) { echo 1; } else { echo round($time, 1, PHP_ROUND_HALF_UP); } }
Để hiển thị ra ngoài, bạn chỉ cần dán đoạn code dưới vào chỗ muốn hiển thị.
PHP
<?php echo post_word_count(); ?>
Thêm nhóm thành viên quản trị
PHP
$add_group_user = add_role('Creator', __('Creator'), array( 'upload_files' => true, // File downloads are allowed 'edit_others_pages' => true, // Page editing is allowed 'edit_posts' => true, // Permission to edit posts 'publish_posts' => true, // Permission to review articles 'read' => true, 'level_3' => true, ) );
Sử dụng font chữ Google cho WordPress
PHP
function google_fonts() { wp_register_style( 'OpenSans', 'https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' ); wp_enqueue_style( 'OpenSans' ); } add_action( 'wp_print_styles', 'google_fonts' );
Hiển thị thời gian ở mục bình luận như Facebook
PHP
function pressfore_comment_time_output(date,d, $comment){
return sprintf(_x('%s trước', '%s = human-readable time difference', 'your-text-domain'), human_time_diff(get_comment_time('U'), current_time('timestamp')));
}
add_filter('get_comment_date', 'pressfore_comment_time_output', 10, 3);
Tắt Widget không dùng tới
PHP
add_action( 'widgets_init', function () { unregister_widget( 'WP_Widget_Pages' ); unregister_widget( 'WP_Widget_Calendar' ); unregister_widget( 'WP_Widget_Archives' ); unregister_widget( 'WP_Widget_Links' ); unregister_widget( 'WP_Widget_Meta' ); unregister_widget( 'WP_Widget_Search' ); unregister_widget( 'WP_Widget_Text' ); unregister_widget( 'WP_Widget_Categories' ); unregister_widget( 'WP_Widget_Recent_Posts' ); unregister_widget( 'WP_Widget_Recent_Comments' ); unregister_widget( 'WP_Widget_RSS' ); unregister_widget( 'WP_Widget_Tag_Cloud' ); unregister_widget( 'WP_Nav_Menu_Widget' ); }, 11);
Chỉ Admin mới được phép truy cập vào trình quản lý WordPress
PHP
function lovend_redirect(){ $kiemtra = get_current_user_id(); if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('editor') || current_user_can('author') || current_user_can('subscriber') || current_user_can('contributor') ) ){ wp_redirect( home_url() ); exit; } } add_action('init','lovend_redirect');
Thêm ô nhập thông tin cho thành viên ở hồ sơ thành viên
PHP
function add_fields_user($profile_fields){ profilefields[′phone′]=′Phone′;profile_fields['namsinh'] = 'Dob'; profilefields[′facebook′]=′Facebook′;returnprofile_fields; } add_filter('user_contactmethods', 'add_fields_user');
Bỏ menu không cần thiết trong trình quản lý WordPress
PHP
add_action( 'admin_menu', function () { // Remove Dashboard remove_menu_page('index.php'); // Remove Posts remove_menu_page('edit.php'); // Remove Posts -> Categories remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=category'); // Remove Posts -> Tags remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag'); // Remove Media remove_menu_page('upload.php'); // Remove Media -> Library remove_submenu_page('upload.php', 'upload.php'); // Remove Media -> Add new media remove_submenu_page('upload.php', 'media-new.php'); // Remove Pages remove_menu_page('edit.php?post_type=page' ); // Remove Pages -> All pages remove_submenu_page( 'edit.php?post_type=page', 'edit.php?post_type=page'); // Remove Pages -> Add new page remove_submenu_page('edit.php?post_type=page', 'post-new.php?post_type=page'); // Remove Comments remove_menu_page('edit-comments.php'); // Remove Appearance remove_menu_page( 'themes.php' ); // Remove Appearance -> Themes remove_submenu_page('themes.php', 'themes.php'); // Remove Appearance -> Customize remove_submenu_page('themes.php', 'customize.php?return=' . urlencode($_SERVER['REQUEST_URI'])); // Remove Appearance -> Widgets remove_submenu_page('themes.php', 'widgets.php'); // Remove Appearance -> Menus remove_submenu_page('themes.php', 'nav-menus.php.php'); // Remove Appearance -> Editor remove_submenu_page('themes.php', 'theme-editor.php'); // Remove Plugins remove_menu_page('plugins.php'); // Remove Plugins -> Installed plugins remove_submenu_page('plugins.php', 'plugins.php'); // Remove Plugins -> Add new plugins remove_submenu_page('plugins.php', 'plugin-install.php'); // Remove Plugins -> Plugin editor remove_submenu_page('plugins.php', 'plugin-editor.php'); // Remove Users remove_menu_page('users.php'); // Remove Users -> Users remove_submenu_page('users.php', 'users.php'); // Remove Users -> New user remove_submenu_page('users.php', 'user-new.php'); // Remove Users -> Your profile remove_submenu_page('users.php', 'profile.php'); // Remove Tools remove_menu_page('tools.php'); // Remove Tools -> Available Tools remove_submenu_page('tools.php', 'tools.php'); // Remove Tools -> Import remove_submenu_page('tools.php', 'import.php'); // Remove Tools -> Export remove_submenu_page('tools.php', 'export.php'); // Remove Settings remove_menu_page('options-general.php'); // Remove Settings -> Writing remove_submenu_page('options-general.php', 'options-writing.php'); // Remove Settings -> Reading remove_submenu_page('options-general.php', 'options-reading.php'); // Remove Settings -> Discussion remove_submenu_page('options-general.php', 'options-discussion.php'); // Remove Settings -> Media remove_submenu_page('options-general.php', 'options-media.php'); // Remove Settings -> Permalinks remove_submenu_page('options-general.php', 'options-permalink.php'); }, 999);
Xóa nhóm thành viên mặc định trên WordPress
PHP
add_action( 'admin_init', function () { remove_role('administrator'); remove_role('editor'); remove_role('author'); remove_role('contributor'); remove_role('subscriber'); });
Bỏ các chức năng không cần thiết trong mục Media
PHP
add_filter('media_view_strings', function ( $strings ) { strings[′createGalleryTitle′]=null;strings['createPlaylistTitle'] = null; strings[′createVideoPlaylistTitle′]=null;strings['insertFromUrlTitle'] = null; return $strings; });
Tags:
wordpress