Blog cá nhân
Bài viết mới nhất
Chia sẻ kinh nghiệm thực tế về WordPress, lập trình và phát triển web.
Trang 10 / 12 — 111 bài viết

Cách giảm thời gian phản hồi máy chủ khi sử dụng admin-ajax.php hoặc REST API
Bạn hãy gián đoạn mã sau vào theme của bạn, vd: functions.php add_filter( ‘option_active_plugins’, ‘tmdev_exclude_plugins’ ); function tmdev_exclude_plugins( $plugins ) { /** * If we’re not performing our AJAX request, return early. */ if ( ! defined( ‘DOING_AJAX’ ) || ! DOING_AJAX || ! isset( $_REQUEST[‘action’] ) || ‘your_action_request’ !== $_REQUEST[‘action’] ) { return $plugins; […]

Hướng dẫn dịch và tạo biến dịch trong theme WordPress
https://developer.wordpress.org/themes/functionality/internationalization/

Thiết lập hình ảnh đại diện mặc định là hình ảnh đầu tiên trong nội dung bài viết
add_action( 'wp_footer', 'set_post_thumbnail_post_type_projects' ); function set_post_thumbnail_post_type_projects(){ $args = array( 'posts_per_page' => -1, 'post_type' => 'projects', ); $query = new WP_Query( $args ); if( $query->have_posts() && is_user_logged_in() ){ while ( $query->have_posts() ) { $query->the_post(); $content = get_the_content(); $post_id = get_the_ID(); if ( preg_match_all( '/<img [^>]+>/', $content, $matches ) ) { foreach ( (array) $matches[0] as $image […]

Hiển thị chú thích hình ảnh khi popup trong chi tiết bài viết sử dụng gallery
Khi ta sử dụng các plugin popup thì sẽ không hiển thị phần chú thích của hình ảnh. Vì vậy trong bài viết này mình sẽ hướng dẫn các bạn hiển thị chú thích hình ảnh khi popup ảnh. Các bước thực hiện: Tạo thư viện ảnh trong chi tiết bài viết Thêm thư viện […]

Định dạng số điện thoại
Tại sao phải định dạng lại số điện thoại Đẹp và dễ nhìn hơn Xuất số điện thoại ra excel không bị mất số 0 đầu tiên Cách định dạng lại số điện thoại trong php $sdt = '1234999999'; if( preg_match( '/^(\d{4})(\d{3})(\d{3})$/', $sdt, $matches ) ){ $sdt = $matches[1] . ' ' .$matches[2] . ' […]

Hướng dẫn tạo selectbox lọc theo chuyên mục của custom post type WordPress
Xác định taxonomy (chuyên mục) cần lọc: vd: Taxonomy của bài viết là: category, post_tag Để lấy taxonomy của custom post type bất kỳ thì bạn hãy làm theo các bước sau: Hình ảnh bên dưới post type là: wpb_fp_portfolio và taxonomy là: wpb_fp_portfolio_cat Viết hàm lọc taxonomy cho custom post type add_action( 'restrict_manage_posts', 'wpb_fp_portfolio_filter', 10, 2 ); function […]

Thêm nút xuất dữ liệu ra excel trong post type WordPress
Viết sự kiện xuất dữ liệu ra Excel Để xuất được dữ liệu ra file excel ta cần sử dụng 1 thư viện: PHPexcel Các bước xuất dữ liệu: B1: Thêm thư viện PHPexcel B2: Truy vấn để lấy dữ liệu cần xuất Viết button xuất dữ liệu Hook thêm nút trong post type: […]

Mã hoá hình ảnh thành Base64 Encoder
Tại sao chúng ta nên mã hoá hình ảnh Cách mã hoá hình ảnh Truy cập trang: https://www.giftofspeed.com/base64-encoder/ để mã hoá hình ảnh

Tắt zoom website trên mobile
Để tắt chế độ zoom website dưới mobi ta chỉ cần dán đoạn mã sau vào trước thẻ đóng của </head> <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/> <meta name='apple-mobile-web-app-capable' content='yes' /> Để kiểm tra đoạn mã bạn nhúng đã chính xác chưa bạn chỉ cần “view-source” hoặc nhấn phím tắt F12 để kiểm tra Sau […]

Lấy tất cả danh mục theo post id của Custom Post Type
//Returns All Term Items for "my_taxonomy". $term_list = wp_get_post_terms( $post->ID, 'my_taxonomy', array( 'fields' => 'all' ) ); print_r( $term_list ); // Returns Array of Term Names for "my_taxonomy". $term_list = wp_get_post_terms( $post->ID, 'my_taxonomy', array( 'fields' => 'names' ) ); print_r( $term_list ); // Returns Array of Term ID's for "my_taxonomy". $term_list = wp_get_post_terms( $post->ID, 'my_taxonomy', […]