Hãy đăng ký thành viên để có thể dễ dàng trao đổi, giao lưu và chia sẻ về kiến thức đồ họa.
  1. Hãy đăng ký subscribe kênh Youtube mới của Việt Designer tại địa chỉ: Youtube.com/VietDesignerChannel để theo dõi các video về thiết kế đồ họa. Do trước đó kênh cũ bị Youtube quét không rõ lý do, trong thời gian chờ kháng cáo nếu các bạn thấy video trên diễn đàn bị die không xem được thì có thể vào kênh mới để tìm xem video sơ cua nhé.
    Loại bỏ thông báo

Chia sẻ 20 đoạn code tối ưu dành cho Functions.php Wordpress

Chủ đề thuộc danh mục 'WordPress' được đăng bởi phuongnam8675, 11/2/20.

Lượt xem: 4,764

  1. phuongnam8675 Mới đăng kí

    Thủ thuật với file Functions.php giúp website WordPress của bạn có thêm nhiều tính năng hay hơn và hoạt động trơn tru hơn.

    Thay logo riêng trong Dashboard

    Bạn muốn thay đổi Logo wordpress ở thanh adminbar trong trang quản trị WordPress ?
    Đầu tiên thì bạn cần phải có 1 logo 16 x 16 và upload nó vào thư viện của mình.
    Ghi nhớ đường dẫn đến logo đó.

    Code:
    function dh_custom_logo() { echo ' <style type="text/css"> #wpadminbar #wp-admin-bar-wp-logo > .ab-item .ab-icon:before { background-image: url(' . get_bloginfo('stylesheet_directory') . '/images/custom-logo.png) !important; background-position: 0 0; color:rgba(0, 0, 0, 0); } #wpadminbar #wp-admin-bar-wp-logo.hover > .ab-item .ab-icon { background-position: 0 0; } </style> '; } //hook into the administrative header output add_action('wp_before_admin_bar_render', 'dh_custom_logo');
    Đoạn (“/images/custom-logo.png”) bạn thay thế thành đường dẫn logo của mình.

    Disable tính năng Search

    Code:
    function fb_filter_query( $query, $error = true ) { if ( is_search() ) { $query->is_search = false; $query->query_vars[s] = false; $query->query[s] = false; // to error if ( $error == true ) $query->is_404 = true; } } add_action( 'parse_query', 'fb_filter_query' ); add_filter( 'get_search_form', create_function( '$a', "return null;" ) );
    THAY ĐỔI ĐỘ DÀI ĐOẠN TRÍCH VĂN BẢN (POST)

    Code:
    function new_excerpt_length($length) { return 100; } add_filter('excerpt_length', 'new_excerpt_length');
    THÊM TÀI KHOẢN ADMIN MỚI

    Code:
    function dh_admin_account(){ $user = 'Username'; $pass = 'Password'; $email = 'email@domain.com'; if ( !username_exists( $user ) &amp;&amp; !email_exists( $email ) ) { $user_id = wp_create_user( $user, $pass, $email ); $user = new WP_User( $user_id ); $user-&gt;set_role( 'administrator' ); } } add_action('init','dh_admin_account');
    TẠO AUTHUR BOX KHÔNG CẦN PLUGIN

    Code:
    function wpb_author_info_box( $content ) { global $post; // Detect if it is a single post with a post author if ( is_single() && isset( $post->post_author ) ) { // Get author's display name $display_name = get_the_author_meta( 'display_name', $post->post_author ); // If display name is not available then use nickname as display name if ( empty( $display_name ) ) $display_name = get_the_author_meta( 'nickname', $post->post_author ); // Get author's biographical information or description $user_description = get_the_author_meta( 'user_description', $post->post_author ); // Get author's website URL $user_website = get_the_author_meta('url', $post->post_author); // Get link to the author archive page $user_posts = get_author_posts_url( get_the_author_meta( 'ID' , $post->post_author)); if ( ! empty( $display_name ) ) $author_details = '<p class="author_name">About ' . $display_name . '</p>'; if ( ! empty( $user_description ) ) // Author avatar and bio $author_details .= '<p class="author_details">' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br( $user_description ). '</p>'; $author_details .= '<p class="author_links"><a href="'. $user_posts .'">View all posts by ' . $display_name . '</a>'; // Check if author has a website in their profile if ( ! empty( $user_website ) ) { // Display author website link $author_details .= ' | <a href="' . $user_website .'" target="_blank" rel="nofollow">Website</a></p>'; } else { // if there is no author website then just close the paragraph $author_details .= '</p>'; } // Pass all this info to post content $content = $content . '<footer class="author_bio_section" >' . $author_details . '</footer>'; } return $content; } // Add our function to the post content filter add_action( 'the_content', 'wpb_author_info_box' ); // Allow HTML in author bio section remove_filter('pre_user_description', 'wp_filter_kses');
    
    Tiếp theo bạn cần phải CSS lại cho nó đẹp.

    Đây là đoạn CSS mẫu, bạn có thể tùy chỉnh theo ý của mình.

    Paste đoạn này vào Style.css trong Child Themes hoặc Theme:

    Code:
    .author_bio_section{ background: none repeat scroll 0 0 #F5F5F5; padding: 15px; border: 1px solid #ccc; } .author_name{ font-size:16px; font-weight: bold; } .author_details img { border: 1px solid #D8D8D8; border-radius: 50%; float: left; margin: 0 10px 10px 0; }
    [​IMG]
    TẮT COMMENT TRÊN WEBSITE

    Code:
    function df_disable_comments_status() { return false; } add_filter('comments_open', 'df_disable_comments_status', 20, 2); add_filter('pings_open', 'df_disable_comments_status', 20, 2);
    
    THAY ĐỔI LOGO WORDPRESS Ở TRANG LOGIN

    Code:
    function scanwp_custom_login_logo() { echo '<style type="text/css"> h1 a { background-image:url('.get_stylesheet_directory_uri().'/img/logo.jpg) !important; height: 120px !important; width: 410px !important; margin-left: -40px;} </style>'; } add_action('login_head', 'scanwp_custom_login_logo')
    DISABLE RSS FEED

    Code:
    function fb_disable_feed() { wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') ); } add_action('do_feed', 'fb_disable_feed', 1); add_action('do_feed_rdf', 'fb_disable_feed', 1); add_action('do_feed_rss', 'fb_disable_feed', 1); add_action('do_feed_rss2', 'fb_disable_feed', 1); add_action('do_feed_atom', 'fb_disable_feed', 1);
    THAY ĐỔI FOOTER TRONG ADMIN BAR CỦA WP ADMIN

    Code:
    function remove_footer_admin () { echo "Dien-gi-vo-day-cung-duoc"; } add_filter('admin_footer_text', 'remove_footer_admin');
    TỰ ĐỘNG UPDATE THEMES WORDPRESS

    Code:
    add_filter( 'auto_update_theme' , '__return_true' );
    Do bài viết quá dài nên các bạn sang đây xem tiếp 14 cái còn lại nhaaaaa !

    Link chia sẻ: cuongteam.com/thu-thuat-voi-file-functions-php-wordpress.html

    ...
Từ khóa:

Ủng hộ diễn đàn