• Về minhduy.vn
  • Đăng ký Hosting
  • Thiết kế Website
  • Khuyến mãi HOT
Hướng Dẫn Sử Dụng Dịch Vụ - Minh Duy Solutions
  • Trang chủ
  • Hosting
    • Hướng dẫn Hosting cPanel
    • Hướng dẫn Hosting DirectAdmin
  • Tên miền
  • Website
    • Hướng dẫn WordPress
    • Hướng dẫn Webmaster
  • Email Doanh Nghiệp
    • Office 365
    • Google Work Space
    • Email Zimbra
  • VPS – Máy chủ
    • Hướng dẫn Linux
    • Hướng dẫn DirectAdmin
  • Hướng dẫn chung
  • Góc ICT
No Result
View All Result
  • Trang chủ
  • Hosting
    • Hướng dẫn Hosting cPanel
    • Hướng dẫn Hosting DirectAdmin
  • Tên miền
  • Website
    • Hướng dẫn WordPress
    • Hướng dẫn Webmaster
  • Email Doanh Nghiệp
    • Office 365
    • Google Work Space
    • Email Zimbra
  • VPS – Máy chủ
    • Hướng dẫn Linux
    • Hướng dẫn DirectAdmin
  • Hướng dẫn chung
  • Góc ICT
No Result
View All Result
Hướng Dẫn Sử Dụng Dịch Vụ - Minh Duy Solutions
No Result
View All Result
Home Hướng dẫn Website Hướng dẫn WordPress

Tổng hợp Functions hay dùng trong WordPress

Minh Duy Solutions by Minh Duy Solutions
17/06/2023
Reading Time: 7 mins read
A A
0
tong hop functions hay dung trong wordpress 3844
579
SHARES
1.9k
VIEWS
Share on FacebookShare on Twitter

tong hop functions hay dung trong wordpress 3844

Bài viết tổng hợp những Function hay và được sử dụng nhiều trong WordPress, thay thế phần nào việc sử dụng thêm Plugin, giúp tối ưu tốc độ tải trang. . .

Kiểm tra định dạng số điện thoại 10 số Việt Nam

function check_wpcf7_tel( $result, $tel ) { 
  $result = preg_match( '/^(0|\+84)(\s|\.)?((3[2-9])|(5[689])|(7[06-9])|(8[1-689])|(9[0-46-9]))(\d)(\s|\.)?(\d{3})(\s|\.)?(\d{3})$/', $tel );
  return $result; 
}

add_filter( 'wpcf7_is_tel', 'check_wpcf7_tel', 10, 2 );

Code phân trang cho bài viết

//Code phan trang
function wiki_wp_corenavi($custom_query = null, $paged = null) {
    global $wp_query;
    if($custom_query) $main_query = $custom_query;
    else $main_query = $wp_query;
    $paged = ($paged) ? $paged : get_query_var('paged');
    $big = 999999999;
    $total = isset($main_query->max_num_pages)?$main_query->max_num_pages:'';
    if($total > 1) echo '<div class="pagenavi">';
    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, $paged ),
        'total' => $total,
        'mid_size' => '10', // Số trang hiển thị khi có nhiều trang trước khi hiển thị ...
        'prev_text'    => __('<i class="icon-angle-left"></i>','wiki'),
        'next_text'    => __('<i class="icon-angle-right"></i>','wiki'),
    ) );
    if($total > 1) echo '</div>';
}

Thêm Panel trong Dashboard

add_action( 'admin_footer', 'rv_custom_dashboard_widget' );
function rv_custom_dashboard_widget() {
    // Bail if not viewing the main dashboard page
    if ( get_current_screen()->base !== 'dashboard' ) {
        return;
    }
    ?>
    
    <div id="custom-id" style="display: none;border: 2px solid #52accc; padding: 0 20px">
    <h2 style="margin-top:20px; text-transform:uppercase; color: #dd3333; margin-bottom:-10px">Về chúng tôi</h2>	
    <h3>CÔNG TY TNHH TM & DỊCH VỤ FOREST JUMP VIỆT NAM</h3>
    <p style="color: #000"><strong>Địa chỉ: </strong>P3432 HH4B Linh Đàm - Hoàng Liệt - Hoàng Mai - Hà Nội</p>
    <p style="color: #000"><strong>Hotline: </strong><a style="text-decoration:none" href="tel:0888805078">0888 805 078</a></p>
    <p style="color: #000"><strong>Email: </strong><a style="text-decoration:none" href="mailto:lienhe@forestjump.com.vn">lienhe@forestjump.com.vn</a></p>
    <p style="color: #000"><strong>Website: </strong><a href="https://forestjump.com.vn" style="text-decoration:none">Forestjump.com.vn</a></p>
    </div>
    <script>
        jQuery(document).ready(function($) {
            $('#welcome-panel').after($('#custom-id').show());
        });
    </script>

<?php }

Đổi font chữ từ pt sang px

function flatsome_editor_text_sizes($initArray){
    $initArray['fontsize_formats'] = "9px 10px 12px 13px 14px 16px 17px 18px 19px 20px 21px 24px 28px 32px 36px";
    return $initArray;
};

Thêm Page Options trong quản trị

// Page Options
if( function_exists('acf_add_options_page') ) {
    acf_add_options_page(array(
        'page_title' 	=> 'Cài đặt chung', // Title hiển thị khi truy cập vào Options page
        'menu_title'	=> 'Cài đặt chung', // Tên menu hiển thị ở khu vực admin
        'menu_slug' 	=> 'cai-dat-chung', // Url hiển thị trên đường dẫn của options page
        'capability'	=> 'edit_posts',
        'redirect'	=> false
    ));
}

Xóa thông báo kích hoạt Flatsome trong quản trị

add_action( 'init', 'hide_notice' );
function hide_notice() {
remove_action( 'admin_notices', 'flatsome_maintenance_admin_notice' );
}

Xóa trường thông tin trong form đặt hàng

add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 
);
function wc_npr_filter_phone( $address_fields ) {
    $address_fields['billing_phone']['required'] = true;
    $address_fields['billing_country']['required'] = false;
    $address_fields['billing_last_name']['required'] = false;
    $address_fields['billing_city']['required'] = false;
    $address_fields['billing_postcode']['required'] = false;
    $address_fields['billing_email']['required'] = false;
    $address_fields['billing_state']['required'] = false;
    $address_fields['billing_address_1']['required'] = true;
    $address_fields['billing_address_2']['required'] = false;
    return $address_fields;

}

//make shipping fields not required in checkout
add_filter( 'woocommerce_shipping_fields', 
'wc_npr_filter_shipping_fields', 10, 1 );
function wc_npr_filter_shipping_fields( $address_fields ) {
    $address_fields['shipping_first_name']['required'] = true;
    $address_fields['shipping_last_name']['required'] = false;
    $address_fields['shipping_phone']['required'] = true;
    $address_fields['shipping_address_1']['required'] = true;
    $address_fields['shipping_address_2']['required'] = false;
    $address_fields['shipping_city']['required'] = false;
    $address_fields['shipping_country']['required'] = false;
    $address_fields['shipping_postcode']['required'] = false;
    $address_fields['shipping_state']['required'] = false;
    
    return $address_fields;
}
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     unset($fields['billing']['billing_company']);
     //unset($fields['billing']['billing_address_1']);
     unset($fields['billing']['billing_last_name']);
     unset($fields['billing']['billing_address_2']);
     unset($fields['billing']['billing_country']);
     unset($fields['billing']['billing_city']);
     unset($fields['billing']['billing_state']);
     unset($fields['billing']['billing_postcode']);
     //unset($fields['billing']['billing_email']);
      unset($fields['shipping']['shipping_company']);
     //unset($fields['billing']['billing_address_1']);
     unset($fields['shipping']['shipping_last_name']);
     unset($fields['shipping']['shipping_address_2']);
     unset($fields['shipping']['shipping_country']);
     unset($fields['shipping']['shipping_city']);
     unset($fields['shipping']['shipping_state']);
     unset($fields['shipping']['shipping_postcode']);
     //unset($fields['shipping']['shipping_email']);
     return $fields;
}

Tạo mã đơn Woocommer tùy chỉnh

//Custom Order Number
add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number' );
function change_woocommerce_order_number( $order_id ) {
    $prefix = 'BEAR';
    $suffix = 'ONL';
    $new_order_id = $prefix . $order_id . $suffix;
    return $new_order_id;
}

Xóa thẻ H3 trong tiêu đề bình luận

add_filter( 'comment_form_defaults', 'custom_reply_title' );
function custom_reply_title( $defaults ){
  $defaults['title_reply_before'] = '<span id="reply-title" class="h4 comment-reply-title">';
  $defaults['title_reply_after'] = '</span>';
  return $defaults;
}

Tắt Gutenberg Editor & Gutenberg Widget

// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false', 100 );

// Disables the block editor from managing widgets. renamed from wp_use_widgets_block_editor
add_filter( 'use_widgets_block_editor', '__return_false' );

Dịch ngôn ngữ

//Dịch ngôn ngữ
function multi_change_translate_text( $translated ) {
    $text       = array(
        'Thêm vào giỏ hàng' => 'Đặt mua',
        'Add to cart' => 'Đặt mua',
        'Mô tả' => 'Thông tin sản phẩm',
        'Lựa chọn các tùy chọn' => 'Xem thêm',
        'Cảm ơn bạn. Đơn hàng của bạn đã được nhận.' => 'Cảm ơn bạn! Chúng tôi đã nhận được đơn hàng của bạn.',
    );
    $translated = str_ireplace( array_keys( $text ), $text, $translated );
    return $translated;
}
add_filter( 'gettext', 'multi_change_translate_text', 20 );

Thay khoảng giá bằng giá của biến thể

//Replace Price Range by Variation Price
add_action( 'woocommerce_before_single_product', 'move_variations_single_price', 1 );
function move_variations_single_price(){
  global $product, $post;
  if ( $product->is_type( 'variable' ) ) {
    add_action( 'woocommerce_single_product_summary', 'replace_variation_single_price', 10 );
  }
}

function replace_variation_single_price() {
  ?>
    <style>
      .woocommerce-variation-price {
        display: none;
      }
    </style>
    <script>
      jQuery(document).ready(function($) {
        var priceselector = '.product p.price';
        var originalprice = $(priceselector).html();

        $( document ).on('show_variation', function() {
          $(priceselector).html($('.single_variation .woocommerce-variation-price').html());
        });
        $( document ).on('hide_variation', function() {
          $(priceselector).html(originalprice);
        });
      });
    </script>
  <?php
}

//Save For simple products
add_action( 'woocommerce_single_product_summary', 'simple_product_saving_amount', 11 );
function simple_product_saving_amount() {
    global $product;

    if( $product->is_type('simple') && $product->is_on_sale() ) {
        $regular_price = (float) wc_get_price_to_display( $product, array('price' => $product->get_regular_price() ) );
        $active_price  = (float) wc_get_price_to_display( $product, array('price' => $product->get_sale_price() ) );

        $saved_amount  = $regular_price - $active_price;
        $percentage    = round( $saved_amount / $regular_price * 100 );

        echo '<p id="saving_rpice">'. __("Tiết kiệm") .': ' . wc_price($saved_amount) . ' ('.$percentage.'%)</p>';
    }
}

//Save For product variations (on variable products)
add_filter( 'woocommerce_available_variation', 'variable_product_saving_amount', 10, 3 );
function variable_product_saving_amount( $data, $product, $variation ) {

    if( $variation->is_on_sale() ) {
        $saved_amount  = $data['display_regular_price'] - $data['display_price'];
        $percentage    = round( $saved_amount / $data['display_regular_price'] * 100 );

        $data['price_html'] .= '<p id="saving_rpice">'. __("Tiết kiệm") .': ' . wc_price($saved_amount) . ' ('.$percentage.'%)</p>';
    }
    return $data;
}

Thay 0đ bằng Liên hệ

// Thay 0đ bằng Liên hệ
function wiki_wc_custom_get_price_html( $price, $product ) {
    if ( $product->get_price() == 0 ) {
        if ( $product->is_on_sale() && $product->get_regular_price() ) {
            $regular_price = wc_get_price_to_display( $product, array( 'qty' => 1, 'price' => $product->get_regular_price() ) );
 
            $price = wc_format_price_range( $regular_price, __( 'Free!', 'woocommerce' ) );
        } else {
            $price = '<span class="amount">' . __( 'Liên hệ', 'woocommerce' ) . '</span>';
        }
    }
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'wiki_wc_custom_get_price_html', 10, 2 );

Thêm Widget Area

register_sidebar( array(
    'name' => 'Contact Menu',
    'id' => 'contactmenu',
    'description' => 'Widget for Contact Menu',
    'before_widget' => '<div class="contact-menu">',
    'after_widget' => '</div>',
    'before_title' => '<span class="widget-title">',
    'after_title' => '</span>',
    ) );

Xóa Menu iTem trong trang quản trị

// admin_init action works better than admin_menu in modern wordpress (at least v5+)
add_action( 'admin_init', 'my_remove_menu_pages' );
function my_remove_menu_pages() {


  global $user_ID;

  if ( $user_ID != 1 ) { //your user id

   remove_menu_page('edit.php'); // Posts
   remove_menu_page('upload.php'); // Media
   remove_menu_page('link-manager.php'); // Links
   remove_menu_page('edit-comments.php'); // Comments
   remove_menu_page('edit.php?post_type=page'); // Pages
   remove_menu_page('plugins.php'); // Plugins
   remove_menu_page('themes.php'); // Appearance
   remove_menu_page('users.php'); // Users
   remove_menu_page('tools.php'); // Tools
   remove_menu_page('options-general.php'); // Settings
  }
}

Ẩn thông báo trong trang quản trị

add_action('admin_head', 'bc_disable_notice'); function bc_disable_notice() { ?> <style> #message { display: none;} </style> <?php }

Tắt cập nhật tự động Theme và Plugin

Thêm vào functions.php

// Disable Auto Update Themes
add_filter( 'auto_update_theme', '__return_false' );
// Disable Auto Update Plugins
add_filter( 'auto_update_plugin', '__return_false' );

Tắt cài đặt Themes – Plugins

define('DISALLOW_FILE_MODS',true);

 

4.8/5 - (175 bình chọn)
Tags: WordPressFunctions
Share232Tweet145
Minh Duy Solutions

Minh Duy Solutions

Bài viết liên quan

stop wordpress user registration spam
Hướng dẫn WordPress

Hướng dẫn xoá hàng loạt user spam trên WordPress

23/05/2025
1.5k
thanh top woo c
Hướng dẫn Website

Hướng dẫn ẩn thanh Edit Product che mất tùy chọn khi đăng sản phẩm của WooComerce

24/09/2024
1.6k
flatsome theme 1
Hướng dẫn Website

Hướng dẫn tắt UXBuilder ở 1 số post type theme Flatsome

24/09/2024
1.6k
flatsome theme 1
Hướng dẫn Website

Bật UX Builder cho Custom post type trên theme Flatsome

24/09/2024
1.7k
Contact Form 7
Hướng dẫn Website

Chống spam cho plugin Contact Form 7

19/06/2024
1.5k
Contact Form 7
Hướng dẫn WordPress

Hướng dẫn cách truyền tiêu đề bài viết, sản phẩm vào Contact Form 7

19/06/2024
1.6k

Để lại một bình luận Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

No Result
View All Result

Recommended.

cPanel and whm

Hướng dẫn xoá cPanel Logs trong 1 câu lệnh

09/08/2024
1.5k
df4857f61b8f21529a251a29271076cd

Hướng dẫn cài đặt NGINX + Apache trên Directadmin

02/10/2022
1.7k

Trending.

cach tao doi quoc gia cho tai khoan google 4082

Cách tạo (đổi quốc gia) cho tài khoản Google

24/01/2024
24.2k
cach tao doi quoc gia cho tai khoan google 4082

Cách xóa hồ sơ thanh toán tài khoản Google

24/01/2024
5.5k
57acc582dde37df0a76107d2fb2448d8

Cách Ngắt Link Ảnh Trong Adobe Illustrator, Đơn Giản, Hiệu Quả

04/10/2022
16.1k
Microsoft Support and Recovery Assistant

Hướng dẫn gỡ bỏ tận gốc Microsoft Office ra khỏi máy tính bằng phần mềm của Microsoft

22/07/2024
2.4k

Hướng dẫn yêu cầu Canva hủy gói đăng ký và yêu cầu hoàn tiền Canva

12/04/2025
2.1k
Wiki Minh Duy Solutions

WIKI.MINHDUY.VN

Chuyên trang hướng dẫn sử dụng dịch vụ của Minh Duy Solutions

DMCA.com Protection Status

Danh mục

  • aaPanel
  • Góc ICT
  • Thiết Kế Đồ Hoạ
  • SEO
  • Hướng dẫn WHMCS
  • Hướng dẫn Hosting
  • Hướng dẫn WordPress
  • Email Zimbra
  • Hướng dẫn DirectAdmin
  • Hướng dẫn Hosting cPanel
  • Office 365
  • Hướng dẫn Website
  • Hướng dẫn Linux
  • Hướng dẫn Hosting DirectAdmin
  • Google Work Space
  • Hướng dẫn Webmaster
  • Hướng dẫn máy chủ
  • Hướng dẫn Email Doanh Nghiệp
  • Hướng dẫn Tên miền
  • Hướng dẫn chung
  • Uncategorized

Thẻ

AFC apt-get update apt-get upgrade category chủ thể cPanel debian DirectAdmin email doanh nghiệp Environment Variables giải nén Google Workspace G Suite hosting ioncube khôi phục mật khẩu linux nginx nmap nodejs npm Office 365 OneDrive Outlook out of memory path Paypal phpmyadmin SMTP. GMail SSH sudo swap Symbolic Link tar tar.gz thông báo tên miền tên miền ubuntu user whois WooCommerce WordPress wordpress cơ bản wp rocket Zimbra
  • Về minhduy.vn
  • Đăng ký Hosting
  • Thiết kế Website
  • Khuyến mãi HOT

Copyright © 2021 Hướng dẫn Minh Duy Solutions

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

×
    No Result
    View All Result
    • Trang chủ
    • Hosting
      • Hướng dẫn Hosting cPanel
      • Hướng dẫn Hosting DirectAdmin
    • Tên miền
    • Website
      • Hướng dẫn WordPress
      • Hướng dẫn Webmaster
    • Email Doanh Nghiệp
      • Office 365
      • Google Work Space
      • Email Zimbra
    • VPS – Máy chủ
      • Hướng dẫn Linux
      • Hướng dẫn DirectAdmin
    • Hướng dẫn chung
    • Góc ICT

    Copyright © 2021 Hướng dẫn Minh Duy Solutions