twentytenのテーマで作成者を非表示にするで検索すると、主に2つの方法があるようです。
- style.css(wp-content/themes/twentyten/style.css)を編集で非表示にする方法
- functions.php(wp-content/themes/twentyten/functions.php)のtwentyten_posted_on関数を編集し非表示にする方法
style.cssはHTMLソースでは表示されているが、CSS該当部分は非表示となる。CSSは正直よくわからないのでそんな物なのかもしれない。
2のfunctions.phpを編集して非表示にする方法を見たとき疑問を感じました。これだけwordpressが使われていてtwentyten_posted_on関数を直接編集するようなつくりになっているんか?標準付属のthemeだからそんなもんなのか?疑問はfunctions.phpを見て解けました。
該当のソースコードは以下です。
if ( ! function_exists( 'twentyten_posted_on' ) ) : /** * Prints HTML with meta information for the current post-date/time and author. * * @since Twenty Ten 1.0 */ function twentyten_posted_on() { printf( __( 'Posted on %2$s %3$s', 'twentyten' ), 'meta-prep meta-prep-author', sprintf( '%3$s', get_permalink(), esc_attr( get_the_time() ), get_the_date() ), sprintf( ' ', get_author_posts_url( get_the_author_meta( 'ID' ) ), esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ), get_the_author() ) ); } endif;
1行目のifできちんとtwentyten_posted_on関数が定義されているか確認されており、わざわざ関数を直接編集しなくとも外部で定義されていれば外部のtwentyten_posted_on関数が動くように設計されている。
wp-config.phpに追記
で、私はfunctions.phpを変更せずにwp-config.phpへ以下を追記し、投稿日だけの表示にしている。
適当に消しただけなので不要なものもあるし、__()関数は無駄な処理だが、目的は達成しているのでいいことにしておこうw
function twentyten_posted_on() { printf( __( '投稿日: %2$s %3$s', 'twentyten' ), 'meta-prep meta-prep-author', sprintf( '%3$s', get_permalink(), esc_attr( get_the_time() ), get_the_date() ), '' ); }