Skip to content

Instantly share code, notes, and snippets.

View Kaiderella's full-sized avatar
🏠
Working from home

Hieu Bui Trung Kaiderella

🏠
Working from home
View GitHub Profile
@Kaiderella
Kaiderella / functions.php
Created March 25, 2017 03:18
Customize Comment Policy
//* Customize Comment Policy
function modify_text_before_comment_form($arg) {
$arg['comment_notes_before'] = '<p class="comment-notes">' . __( 'Lưu ý:</br>> Không sử dụng từ khóa trong mục "Tên". </br>> Hãy sử dụng tên thật và địa chỉ email chính xác.</br>> Vui lòng bình luận bằng tiếng Việt có dấu.</br> Mọi bình luận trái quy định sẽ bị gỡ bỏ link hoặc xóa bỏ hoàn toàn.' ) . '</p>';
return $arg;
}
add_filter('comment_form_defaults', 'modify_text_before_comment_form');
@Kaiderella
Kaiderella / functions.php
Created March 22, 2017 07:30
Sắp xếp danh sách bài viết theo ngày chỉnh sửa
//* Re-order posts list
function orderby_modified_posts( $query ) {
if ($query->is_main_query()) {
$query->set( 'orderby', 'modified' );
}
}
add_action( 'pre_get_posts', 'orderby_modified_posts' );
@Kaiderella
Kaiderella / functions.php
Created March 21, 2017 07:42
Yêu cầu độ dài tối thiểu của bình luận
add_filter( 'preprocess_comment', 'minimal_comment_length' );
function minimal_comment_length( $commentdata ) {
$minimalCommentLength = 20;
if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength ){
wp_die( 'All comments must be at least ' . $minimalCommentLength . ' characters long.' );
}
return $commentdata;
}
@Kaiderella
Kaiderella / functions.php
Created March 21, 2017 07:41
Loại bỏ mục URL trong form bình luận
function remove_comment_fields($fields) {
unset($fields['url']);
return $fields;
}
add_filter('comment_form_default_fields','remove_comment_fields');
@Kaiderella
Kaiderella / functions.php
Created March 21, 2017 07:41
Loại bỏ các trang khỏi kết quả tìm kiếm
function filter_search($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts', 'filter_search');
@Kaiderella
Kaiderella / functions.php
Created March 21, 2017 07:39
Redirect kết quả tìm kiếm về bài viết
add_action('template_redirect', 'redirect_single_post');
function redirect_single_post() {
if (is_search()) {
global $wp_query;
if ($wp_query->post_count == 1 && $wp_query->max_num_pages == 1) {
wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
exit;
}
}
}
@Kaiderella
Kaiderella / functions.php
Created March 21, 2017 07:38
Redirect trang Author Archives về trang About
add_filter( 'author_link', 'my_author_link' );
function my_author_link() {
return home_url( 'about' );
}
@Kaiderella
Kaiderella / wp-config.php
Created March 21, 2017 07:35
Đổi tên thư mục wp-content
define ('WP_CONTENT_FOLDERNAME', 'newfoldername');
@Kaiderella
Kaiderella / wp-config.php
Created March 21, 2017 07:34
Xác định vị trí thư mục wp-content mới
define ('WP_CONTENT_URL', 'http://www.yourwebsite.com/newlocation/wp-content');
@Kaiderella
Kaiderella / wp-config.php
Created March 21, 2017 07:33
Đổi vị trí thư mục wp-content
define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/newlocation/wp-content' );