WordPress 記事詳細に記事公開日と更新日を表示

テーマ「Twenty Seventeen」の記事詳細ページに公開日と、公開日より後に記事を更新した場合は更新日を表示するようにカスタマイズしました。

ついでに公開日・更新日に自分自身へのリンクがあったのではずしました。

外観>テーマの編集>template-tags.php

  1. 変更前
    function twentyseventeen_time_link() {
    	$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,
    		get_the_date( DATE_W3C ),
    		get_the_date(),
    		get_the_modified_date( DATE_W3C ),
    		get_the_modified_date()
    	);
    
    	// Wrap the time string in a link, and preface it with 'Posted on'.
    	return sprintf(
    		/* translators: %s: post date */
    		__( '<span class="screen-reader-text">Posted on</span> %s', 'twentyseventeen' ),
    		'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
    	);
    }

  2. 変更後
    function twentyseventeen_time_link() {
    	$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>公開';
    	if ( get_the_time( 'Y/m/d' ) !== get_the_modified_time( 'Y/m/d' ) ) {
    		$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>公開&nbsp;(<time class="updated published" datetime="%3$s">%4$s</time>更新)';
    	}
    
    	$time_string = sprintf( $time_string,
    		get_the_date( DATE_W3C ),
    		get_the_date(),
    		get_the_modified_date( DATE_W3C ),
    		get_the_modified_date()
    	);
    
    	// Wrap the time string in a link, and preface it with 'Posted on'.
    	return sprintf(
    		/* translators: %s: post date */
    		__( '<span class="screen-reader-text">Posted on</span> %s', 'twentyseventeen' ),
    		$time_string
    	);
    }