init
wpでサイトを作成するときに、細かな設定を毎回行うのは、とても面倒なので、まとめます。
あくまでも My Tips なので悪しからず。
※思い出したら追加していきます
バージョンを非表示に
function remove_wp_version( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_wp_version', 9999 );
add_filter( 'script_loader_src', 'remove_wp_version', 9999 );
ついでに色々非表示に
remove_action('wp_head', 'feed_links_extra', 3 );
remove_action('wp_head', 'wp_generator' );
remove_action('wp_head', 'wlwmanifest_link' );
remove_action('wp_head', 'rsd_link' );
remove_action('wp_head', 'parent_post_rel_link', 10, 0 );
remove_action('wp_head', 'start_post_rel_link', 10, 0 );
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0 );
remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'wp_shortlink_wp_head');
参考:http://elearn.jp/wpman/column/c20110218_01.html
LOGINPAGEのロゴ画像を変更
function custom_login_logo() {
echo '<style type="text/css">h1 a { background: url('.get_bloginfo('template_directory').'/img/logo.png) 50% 50% no-repeat !important; height:41px !important; width:320px !important; }</style>';
}
add_action('login_head', 'custom_login_logo');
フッターのWPリンクの文言変更
function custom_admin_footer() {
echo '<a href="mailto:info@hoge.hoge">お問い合わせ</a>';
}
add_filter('admin_footer_text', 'custom_admin_footer');
メニューの表示設定(権限レベルで判定)
function remove_menus () {
if (!current_user_can('level_10')) {
remove_menu_page('wpcf7'); //Contact Form 7
global $menu;
unset($menu[2]); // ダッシュボード
// unset($menu[4]); // メニューの線1
// unset($menu[5]); // 投稿
// unset($menu[10]); // メディア
// unset($menu[15]); // リンク
// unset($menu[20]); // 固定ページ
unset($menu[25]); // コメント
// unset($menu[59]); // メニューの線2
unset($menu[60]); // テーマ
unset($menu[65]); // プラグイン
// unset($menu[70]); // プロフィール
unset($menu[75]); // ツール
unset($menu[80]); // 設定
// unset($menu[90]); // メニューの線3
}
}
add_action('admin_menu', 'remove_menus');
ダッシュボードのウィジット表示設定(権限レベルで判定)
function example_remove_dashboard_widgets() {
if (!current_user_can('level_10')) {
global $wp_meta_boxes;
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); // 現在の状況
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); // 最近のコメント
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); // 被リンク
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); // プラグイン
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); // クイック投稿
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); // 最近の下書き
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); // WordPressブログ
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); // WordPressフォーラム
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']); // アクティビティ
}
}
add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets');
各種インストール時のFTP回避
// Direct Install/Update
define('FS_METHOD','direct');
xmlrpcを無効化
xmlrpcを使用するケースは、不要
// xmlrpc無効化
add_filter('xmlrpc_enabled', '__return_false');
function remove_xmlrpc($headers) {
unset($headers['X-Pingback']);
return $headers;
}
add_filter('wp_headers', 'remove_xmlrpc');
疑似cron無効化
wp-cronを使用するケースは、不要
// wp-cron無効化
define('DISABLE_WP_CRON', true);