wordpress – hỏi nhanh đáp gọn

Chuyên trang các câu hỏi về WordPress.

Thay đổi kích thước feature image post

Trong theme > functions.php  dòng 199: set_post_thumbnail_size( 604, 270, true );

Chặn các comment spam

Vào dashboard, Settings > Discussion

  • Other comment settings: kiểm Users must be registered and logged in to comment
  • Comment Blacklist: nhập từ khóa của spam nick

link về trang chủ

Trong menu bạn Add một link “trang chủ” thiết lập như sau

Với 1 liên kết bất kỳ trong bài viết hay trong các Widget có hỗ trợ HTML như Text, bạn cho đoạn text hay thẻ <img> (nếu liên kết là hình ảnh) vào giữa thẻ <a> như sau:

<a class=”sidebar-home-link” href=”/”>Home</a>

Thay đổi chữ “Howdy” ở góc trái trên thanh admin bar

Mở file wp-includes > admin-bar.php

tìm đến dòng có chữ Howdy và thay đổi
$avatar = get_avatar( $user_id, 26 );
$howdy  = sprintf( __('Howdy, %1$s'), $current_user->display_name );
$class  = empty( $avatar ) ? '' : 'with-avatar';

Vào trang đăng nhập

Từ số ip http://xxx.xxx.x.xx:81 bạn thêm vào /wp-login.php (hay /wp-admin). Ví dụ như http://192.168.1.100:81/wp-login.php

Annoyed by WordPress asking for FTP username/password?

1.  Locate your WordPress root diectory and find the “wp-config.php” file.

2.  Edit the file and insert this somewhere in the middle as it’s own block, we normally put it after the mysql username/password block.

/*** FTP login settings ***/
define(“FTP_HOST”, “localhost”);
define(“FTP_USER”, “yourftpusername”);
define(“FTP_PASS”, “yourftppassword”);
Of course you’ll want to change “yourftpusername” and “yourftppassword” to the actual FTP usernames/passwords for your site.
Once you’ve made that edit, save the file and voila!  No more punching in your ftp username and password all the time.

link: http://imountain.com/blog/2009/07/13/annoyed-by-wordpress-asking-for-ftp-usernamepassword/

Chỉ hiển thị Home page

<?php if( is_front_page() ) : ?>
<div style=”display:block; height:340px; max-width: 1170px; padding-top: 0px; margin:0px auto; “>
<span style=”float:right; display:block; width: 270px; font-size:22px; font-style:italic; font-family: Times, ‘Times New Roman’, serif; color:#999; padding-right: 30px;”>
“Chỉ có trái tim và trực giác của chính bạn mới biết bạn muốn gì và bạn sẽ trở thành thế nào…”
</span>
<span style=”clear:both; display:block;font-size:12px; display:block; text-align: right; padding-top: 10px; padding-right: 30px; “>~ Steve Jobs.</span>
</div>
<?php else : ?>
<div style=”display:block; height:340px; max-width: 1170px; padding-top: 0px; margin:0px auto; “></div>
<?php endif;?>

if ( is_single()

<?php if ( is_single() && !is_front_page() )

chỉ hiển thị khi mở trang riêng

<?php if ( is_single() ) : ?>
<h2 class=”entry-title”><?php the_title(); ?></h2>
<?php else : ?>
<h3 class=”entry-title”>
<a href=”<?php the_permalink(); ?>” rel=”bookmark”><?php the_title(); ?></a>
</h3>
<?php endif; // is_single() ?>

Sửa chữ “One thought on” trong comment

Trong file wp-content > theme > twentythirteen >  comments.php

<div id=”comments” class=”comments-area”>

<?php if ( have_comments() ) : ?>
<h2 class=”comments-title”>
<?php
printf( _nx( ‘One thought on &ldquo;%2$s&rdquo;’, ‘%1$s thoughts on &ldquo;%2$s&rdquo;’, get_comments_number(), ‘comments title’, ‘twentythirteen’ ),
number_format_i18n( get_comments_number() ), ‘<span>’ . get_the_title() . ‘</span>’ );
?>
</h2>

Sửa chữ “leave a comment” dưới mỗi post
(ngoài trừ sticky post)

Trong file wp-content > theme > twentythirteen >  content.php

<footer class=”entry-meta”>
<?php if ( comments_open() && ! is_single() ) : ?>
<div class=”comments-link”>
<?php comments_popup_link( ‘<span class=”leave-reply”>’ . __( ‘Leave a comment’, ‘twentythirteen’ ) . ‘</span>’, __( ‘One comment so far’, ‘twentythirteen’ ), __( ‘View all comment (%)’, ‘twentythirteen’ ) ); ?>
</div><!– .comments-link –>
<?php endif; // comments_open() ?>

<?php if ( is_single() && get_the_author_meta( ‘description’ ) && is_multi_author() ) : ?>
<?php get_template_part( ‘author-bio’ ); ?>
<?php endif; ?>
</footer>

Đổi chữ “Daily Archives” trong calendar

Trong Archive.php

<h1 class=”archive-title”><?php
if ( is_day() ) :
printf( __( ‘Daily Archives: %s’, ‘twentythirteen’ ), get_the_date() );
elseif ( is_month() ) :
printf( __( ‘Monthly Archives: %s’, ‘twentythirteen’ ), get_the_date( _x( ‘F Y’, ‘monthly archives date format’, ‘twentythirteen’ ) ) );
elseif ( is_year() ) :
printf( __( ‘Yearly Archives: %s’, ‘twentythirteen’ ), get_the_date( _x( ‘Y’, ‘yearly archives date format’, ‘twentythirteen’ ) ) );
else :
_e( ‘Archives’, ‘twentythirteen’ );
endif;
?></h1>

Thay đổi dòng Category Archives.

(wp-content > theme > twentythirteen > category.php)

<header class=”archive-header”>
<h1 class=”archive-title”><?php printf( __( ‘Category Archives: %s’, ‘twentythirteen’ ), single_cat_title( ”, false ) ); ?></h1>

<?php if ( category_description() ) : // Show an optional category description ?>
<div class=”archive-meta”><?php echo category_description(); ?></div>
<?php endif; ?>
</header><!– .archive-header –>

Dãy màu nền trang category

(wp-content > theme > twentythirteen > style.css)

.archive-header {
background-color: rgba(255, 204, 102, 0.3); /*e8e5ce*/
}

Catagory theme

Trong theme: Nhân bản và đổi tên category.php thành category-slug.php (ví dụ: trong category “Ai”, slug= “illustrator” đặt tên category-illustrator.php

image thumbnail size

Trong Dashboard > settings > Media

Chú thích ảnh

(theme > style)

.wp-caption .wp-caption-text,
.entry-caption,
.gallery-caption {
color: #220e10;
font-size: 18px;
font-style: italic;
margin: 0 0 24px;
}

feature image size

(theme > function.php)

set_post_thumbnail_size( 400, 250, true ); /*( 604, 270, true )*/

Sửa form login

Mở file wp-login.php

Đổi logo ở trang đăng nhập

wp-admin > css > login.min.css
background-image:none,url(../images/wordpress-logo.svg?ver=20131107);

Post trang chủ

sửa “Leave a comment”

Trong Theme > content.php

<?php comments_popup_link( ‘<span class=”leave-reply”>’ . __( ‘Leave a comment’, ‘twentythirteen’ ) . ‘</span>’, __( ‘One comment so far‘, ‘twentythirteen’ ), __( ‘View all % comments‘, ‘twentythirteen’ ) ); ?>

Sửa chữ comment trong từng post

Vào wp-includes > comment-template.php

function comment_form( $args = array(), $post_id = null ) {
if ( null === $post_id )
$post_id = get_the_ID();

$commenter = wp_get_current_commenter();
$user = wp_get_current_user();
$user_identity = $user->exists() ? $user->display_name : ”;

$args = wp_parse_args( $args );
if ( ! isset( $args[‘format’] ) )
$args[‘format’] = current_theme_supports( ‘html5’, ‘comment-form’ ) ? ‘html5’ : ‘xhtml’;

$req      = get_option( ‘require_name_email’ );
$aria_req = ( $req ? ” aria-required=’true'” : ” );
$html5    = ‘html5’ === $args[‘format’];
$fields   =  array(
‘author’ => ‘<p class=”comment-form-author”>’ . ‘<label for=”author”>’ . __( ‘Tên đăng nhập’ ) . ( $req ? ‘ <span class=”required”>*</span>’ : ” ) . ‘</label> ‘ .
‘<input id=”author” name=”author” type=”text” value=”‘ . esc_attr( $commenter[‘comment_author’] ) . ‘” size=”30″‘ . $aria_req . ‘ /></p>’,
’email’  => ‘<p class=”comment-form-email”><label for=”email”>’ . __( ‘địa chỉ Email’ ) . ( $req ? ‘ <span class=”required”>*</span>’ : ” ) . ‘</label> ‘ .
‘<input id=”email” name=”email” ‘ . ( $html5 ? ‘type=”email”‘ : ‘type=”text”‘ ) . ‘ value=”‘ . esc_attr(  $commenter[‘comment_author_email’] ) . ‘” size=”30″‘ . $aria_req . ‘ /></p>’,
‘url’    => ‘<p class=”comment-form-url”><label for=”url”>’ . __( ‘Website’ ) . ‘</label> ‘ .
‘<input id=”url” name=”url” ‘ . ( $html5 ? ‘type=”url”‘ : ‘type=”text”‘ ) . ‘ value=”‘ . esc_attr( $commenter[‘comment_author_url’] ) . ‘” size=”30″ /></p>’,
);

$required_text = sprintf( ‘ ‘ . __(‘Các ô thông tin bắt buộc có đánh dấu sao %s’), ‘<span class=”required”>*</span>’ );

/**
* Filter the default comment form fields.
*
* @since 3.0.0
*
* @param array $fields The default comment fields.

“Required fields are marked”

“Your email address will not be published1. Required fields are marked ”
“Leave a Reply1″
*/
$fields = apply_filters( ‘comment_form_default_fields’, $fields );
$defaults = array(
‘fields’               => $fields,
‘comment_field’        => ‘<p class=”comment-form-comment”><label for=”comment”>’ . _x( ‘Nội dung’, ‘noun’ ) . ‘</label> <textarea id=”comment” name=”comment” cols=”45″ rows=”8″ aria-required=”true”></textarea></p>’,
/** This filter is documented in wp-includes/link-template.php */
‘must_log_in’          => ‘<p class=”must-log-in”>’ . sprintf( __( ‘You must be <a href=”%s”>logged in</a> to post a comment.’ ), wp_login_url( apply_filters( ‘the_permalink’, get_permalink( $post_id ) ) ) ) . ‘</p>’,
/** This filter is documented in wp-includes/link-template.php */
‘logged_in_as’         => ‘<p class=”logged-in-as”>’ . sprintf( __( ‘Logged in as <a href=”%1$s”>%2$s</a>. <a href=”%3$s” title=”Log out of this account”>Log out?</a>’ ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( ‘the_permalink’, get_permalink( $post_id ) ) ) ) . ‘</p>’,
‘comment_notes_before’ => ‘<p class=”comment-notes”>’ . __( ‘ www.vietchigo.com sẽ luôn giữ kín email bạn.’ ) . ( $req ? $required_text : ” ) . ‘</p>’,
‘comment_notes_after’  => ‘<p class=”form-allowed-tags”>’ . sprintf( __( ‘You may use these <abbr title=”HyperText Markup Language”>HTML</abbr> tags and attributes: %s’ ), ‘ <code>’ . allowed_tags() . ‘</code>’ ) . ‘</p>’,
‘id_form’              => ‘commentform’,
‘id_submit’            => ‘submit’,
‘name_submit’          => ‘submit’,
‘title_reply’          => __( ‘Thảo luận‘ ),
‘title_reply_to’       => __( ‘Tham gia thảo luận với %s’ ),
‘cancel_reply_link’    => __( ‘Huỷ ý kiến‘ ),
‘label_submit’         => __( ‘Đăng thảo luận‘ ),
‘format’               => ‘xhtml’,
);

Thay “Continue reading” cuối các post là kết quả search

Tìm đoạn code trong theme > function.php

function twentythirteen_excerpt_more( $more ) {
$link = sprintf( ‘<a href=”%1$s” class=”more-link”>%2$s</a>’,
esc_url( get_permalink( get_the_ID() ) ),
/* translators: %s: Name of current post */
sprintf( __( ‘Continue reading %s <span class=”meta-nav”>&rarr;</span>’, ‘twentythirteen’ ), ‘<span class=”screen-reader-text”>’ . get_the_title( get_the_ID() ) . ‘</span>’ )
);
return ‘ &hellip; ‘ . $link;
}
add_filter( ‘excerpt_more’, ‘twentythirteen_excerpt_more’ );
endif;

Chỉ Search trong tiêu đề post

Tìm đoạn code dưới đây trong wp-includes > query.php bỏ phần tô đậm

$search .= $wpdb->prepare( “{$searchand}(($wpdb->posts.post_title LIKE %s) OR ($wpdb->posts.post_content LIKE %s))”, $like, $like );

(Link: https://wordpress.org/support/topic/how-do-i-limit-my-search-on-posts-title-only)

Hoặc thêm đoạn code sau vào theme > functions.php

/* Search post title only*/

function __search_by_title_only( $search, &$wp_query )
{
global $wpdb;
if ( empty( $search ) )
return $search; // skip processing – no search term in query
$q = $wp_query->query_vars;
$n = ! empty( $q[‘exact’] ) ? ” : ‘%’;
$search =
$searchand = ”;
foreach ( (array) $q[‘search_terms’] as $term ) {
$term = esc_sql( like_escape( $term ) );
$search .= “{$searchand}($wpdb->posts.post_title LIKE ‘{$n}{$term}{$n}’)”;
$searchand = ‘ AND ‘;
}
if ( ! empty( $search ) ) {
$search = ” AND ({$search}) “;
if ( ! is_user_logged_in() )
$search .= ” AND ($wpdb->posts.post_password = ”) “;
}
return $search;
}
add_filter( ‘posts_search’, ‘__search_by_title_only’, 500, 2 );

Đổi màu sắc

(wp-content > theme > twentythirteen > style.css)

/* Placeholder text color — selectors need to be separate to work. */
::-webkit-input-placeholder {
color: #7d7b6d;
}

Sửa chữ “Search …” trên menu chính

Đổi chữ wp-include > general-template.php

<label>
<span class=”screen-reader-text”>’ . _x( ‘Search for:’, ‘label’ ) . ‘</span>
<input type=”search” class=”search-field” placeholder=”‘ . esc_attr_x( ‘Search &hellip;’, ‘placeholder’ ) . ‘” value=”‘ . get_search_query() . ‘” name=”s” title=”‘ . esc_attr_x( ‘Search for:’, ‘label’ ) . ‘” />
</label>

Thay đổi ô soạn thảo post

wp-content > theme > twentythirteen > css > editor-style.css

html .mceContentBody {
font-size: 100%;
max-width: 604px;
}

Thêm button superscript và subscript vào thanh công cụ của ô soạn thảo

wp-includes > class-wp-editor.php

function my_mce_buttons_2($buttons) {
/**
* Add in a core button that’s disabled by default
*/
$buttons[] = ‘superscript’;
$buttons[] = ‘subscript’;

return $buttons;
}
add_filter(‘mce_buttons_2’, ‘my_mce_buttons_2’);

Thêm button

/*add more button on tinyMCE toolbar*/
function enable_more_buttons($buttons) {
$buttons[] = ‘hr’;
$buttons[] = ‘sub’;
$buttons[] = ‘sup’;
$buttons[] = ‘fontselect’;
$buttons[] = ‘fontsizeselect’;
$buttons[] = ‘cleanup’;
$buttons[] = ‘styleselect’;

return $buttons;
}
add_filter(“mce_buttons_2”, “enable_more_buttons”); /*mce_buttons_2 = row 2*/

Chuyển Enter thành <br>, Enter_Shift thành <p>

/* Filter Tiny MCE Default Settings */
add_filter( ‘tiny_mce_before_init’, ‘my_switch_tinymce_p_br’ );

/**
* Switch Default Behaviour in TinyMCE to use “<br>”
* On Enter instead of “<p>” *
* @link http://shellcreeper.com/?p=1041
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/tiny_mce_before_init
* @link http://www.tinymce.com/wiki.php/Configuration:forced_root_block
*/
function my_switch_tinymce_p_br( $settings ) {
$settings[‘forced_root_block’] = false;
return $settings;
}

WordPress Editor (TinyMCE) how to create line break <br> and not paragraph <p>.

Leave a Reply