Trang chủ » Blog » Share code tùy biến author meta trong wordpress flatsome với font awesome

Share code tùy biến author meta trong wordpress flatsome với font awesome

Giải thích thì hơi khó cho anh/chị chưa biết về lập trình.

Do thực hiện khá đơn giản nên anh/chị chỉ cần copy và dán đoạn mã sau vào functions.php của theme là sử dụng được luôn anh chị nhé.

Trường hợp 1:

// Kéo cdn font awesome
function gaco_awesome(){
?>
	<link
  rel="stylesheet"
  href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css"
  integrity="sha512-1sCRPdkRXhBV2PBLUdRb4tMg1w2YPf37qatUFeS7zlBy7jJI8Lf4VHwWfZZfpXtYSLy85pkm9GaYVYMfw5BC1A=="
  crossorigin="anonymous"
  referrerpolicy="no-referrer"
/>
<?php
					   }
add_action( 'wp_head', 'gaco_awesome' );
// chỉnh lại header meta trong bài post
function flatsome_posted_on() {
    $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
    if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
        $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
    }
 
    $time_string = sprintf( $time_string,
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() )
    );
 
    $posted_on = sprintf(
        esc_html_x( '%s', 'post date', 'flatsome' ),
        '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
    );
 
    $byline = sprintf(
        esc_html_x( '%s', 'post author', 'flatsome' ),
        '<span class="meta-author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
    );
    echo '<span class="posted-on"><i class="fa fa-calendar" aria-hidden="true"> </i>' . $posted_on . '</span> <span class="byline"><i class="fa fa-user" aria-hidden="true"></i>
 ' . $byline . '</span>';
 
}

Trường hợp 2:

Lưu ý nếu đã kéo và sử dụng font awesome trước đó thì copy code này

// chỉnh lại header meta trong bài post
function flatsome_posted_on() {
    $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
    if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
        $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
    }
 
    $time_string = sprintf( $time_string,
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() )
    );
 
    $posted_on = sprintf(
        esc_html_x( '%s', 'post date', 'flatsome' ),
        '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
    );
 
    $byline = sprintf(
        esc_html_x( '%s', 'post author', 'flatsome' ),
        '<span class="meta-author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
    );
    echo '<span class="posted-on"><i class="fa fa-calendar" aria-hidden="true"> </i>' . $posted_on . '</span> <span class="byline"><i class="fa fa-user" aria-hidden="true"></i>
 ' . $byline . '</span>';
 
}

Chúc anh chị thành công.

0 0 đánh giá
Đánh giá bài viết
Theo dõi
Thông báo của
guest
0 Góp ý
Phản hồi nội tuyến
Xem tất cả bình luận