Chào mừng đến với Diễn Đàn Tin Học VN! Hãy chia sẽ những gì bạn biết, và đưa ra thắc mắc của bạn để được giải đáp.
Một số function đặc biệt dành cho chỉnh sửa và thiết kế theme wordpress
18/11/21, 12:09 am
Khi thiết kế theme wordpress bạn cần phải cần một số function để phục vụ cho yêu cầu của riêng mình, nên hôm nay mình sẽ tổng hợp lại một số function hữu dụng để tiện sử dụng cho cấu hình và chỉnh sử theme của mình cho hợp với ý thích cá nhâ.
Xoá thanh menu admin hiển thị trên trang web khi đăng nhập vào wordpress
Ẩn dashboard không cho hiển thị đối với người dùng không phải là admin của trang web
Xoá bỏ id và class trong thẻ li của navigation menu
Xoá bỏ version phía sau đường link script và css
Chỉnh sửa độ dài tóm tắt bài viết
Xoá thẻ P trong phần tóm tắt độ dài bài viết
Đổi lại đường dẫn cho chức năng search
Thay đổi tên cho danh mục
Xoá dấu ngoặc kép trong thẻ blockquote
Xoá thanh menu admin hiển thị trên trang web khi đăng nhập vào wordpress
- Code:
// Remove Admin bar
function remove_admin_bar()
{
return false;
}
add_filter('show_admin_bar', 'remove_admin_bar'); // Remove Admin bar
Ẩn dashboard không cho hiển thị đối với người dùng không phải là admin của trang web
- Code:
// hidden dashboard
function disable_dashboard() {
if (!is_user_logged_in()) {
return null;
}
if (!current_user_can('administrator') && is_admin()) {
wp_redirect(home_url()); exit;
}
} add_action('admin_init', 'disable_dashboard');
Xoá bỏ id và class trong thẻ li của navigation menu
- Code:
// Remove Injected classes, ID's and Page ID's from Navigation <li> items
function remove_class_id_nav_li($var)
{
return is_array($var) ? array() : '';
}
//add_filter('nav_menu_css_class', 'remove_class_id_nav_li', 100, 1); // Remove Navigation <li> injected classes (Commented out by default)
add_filter('nav_menu_item_id', 'remove_class_id_nav_li', 100, 1); // Remove Navigation <li> injected id (Commented out by default)
add_filter('page_css_class', 'remove_class_id_nav_li', 100, 1); // Remove Navigation <li> Page ID's (Commented out by default)
Xoá bỏ version phía sau đường link script và css
- Code:
// remove version from scripts and styles
function remove_version_scripts_styles($src) {
if (strpos($src, 'ver=')) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter('style_loader_src', 'remove_version_scripts_styles', 9999);
add_filter('script_loader_src', 'remove_version_scripts_styles', 9999);
Chỉnh sửa độ dài tóm tắt bài viết
- Code:
// Custom Excerpts
function wordpress_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'wordpress_excerpt_length', 999 );
Xoá thẻ P trong phần tóm tắt độ dài bài viết
- Code:
// Remove Filters
remove_filter('the_excerpt', 'wpautop'); // Remove <p> tags from Excerpt altogether
Đổi lại đường dẫn cho chức năng search
- Code:
//đổi url cho chức năng search
function wpb_change_search_url() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'wpb_change_search_url' );
Thay đổi tên cho danh mục
- Code:
/* Thay đổi tên cho danh mục */
add_filter( 'get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = sprintf( __( 'Danh mục: %s' ), single_cat_title( '', false ) );
} elseif ( is_tag() ) {
$title = sprintf( __( '%s' ), single_tag_title( '', false ) );
} elseif ( is_author() ) {
$title = sprintf( __( 'Tác giả: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
}//if you want to remove or just change text if you need to
return $title;
});
Xoá dấu ngoặc kép trong thẻ blockquote
- Code:
/**
* remove default curvy quotation marks from blockquote
*/
function blockquote_no_texturzie_tags( $tags ) {
$tags[] = 'blockquote';
return $tags;
}add_filter( 'no_texturize_tags', 'blockquote_no_texturzie_tags' );
Permissions in this forum:
Bạn không có quyền trả lời bài viết
|
|