この記事は最後に更新してから1年以上経過しています。
説明
WordPressのユーザー情報設定ページでは、「名(First name)」の後に「姓(Last name)」を入力するようになっている。日本向けのユーザー登録できるサイトの場合、この並び順はちょっと違和感があるので、「姓」「名」の順に入力できるようにした。
WordPressの管理画面では、table要素によってフォームの各項目を表現しているので、今回のように「名」と「姓」の並びを変更する場合はそれらのtr要素を入れ替えればいい。具体的には、テーマのfunctions.phpに次のコードを追加し、admin_print_footer_scriptsアクションを利用して、「名」と「姓」のあるtr要素を入れ替えた。
add_action( 'admin_print_footer_scripts', 'first_name_after_last_name' );
function first_name_after_last_name() {
?>
<script type="text/javascript">
/* <![CDATA[ */
( function($) {
$( '#last_name' ).each( function () {
tr_last_name = $(this).parents( 'tr' );
tr_first_name = tr_last_name.prev( 'tr' );
if ( tr_first_name.find( '#first_name' ).length == 1 )
tr_last_name.after( tr_first_name );
} );
} )( jQuery );
/* ]]> */
</script>
<?php
}
管理画面の操作できるアクションはいくつか用意されている。今回使用したadmin_print_footer_scriptsアクションは2.8.0で追加されたアクションである。それ以前のバージョンなら、admin_footerアクション(1.2.0以降)が利用できる。
最終更新 : 2013年11月06日 18:44
お勧め
is_home(2018年5月27日 更新)
bool is_home( )
要求されているページが、ホーム(トップ)ページか調べる。
update_comment_meta(2014年3月9日 更新)
bool update_comment_meta( int $comment_id, string $meta_key, mixed $meta_value [ , mixed $prev_value = '' ] )
コメントメタ情報の値を更新する。
wp_robots_noindex(2021年3月13日 更新)
array wp_robots_noindex( array $robots )
robotsメタ要素のcontent属性にnoindexを適用する。
is_taxonomy_hierarchical(2018年5月27日 更新)
bool is_taxonomy_hierarchical( string $taxonomy )
タクソノミーに階層(親子)関係があるか調べる。
get_comment_pages_count(2015年12月16日 更新)
int get_comment_pages_count( [ array $comments = null [ , int $per_page = null [ , bool $threaded = null ] ] ] )
コメントページ数を取得する。