ワードプレスで良く使うコード集

ワードプレスの全ての自動更新を無効化

プラグイン自動更新停止

functions.php

add_filter( 'auto_update_plugin', '__return_false' );
//Wordpressテーマの更新停止
add_filter( 'auto_update_theme', '__return_false' );
wp-config.php

/**自動更新無効 */
define( 'WP_AUTO_UPDATE_CORE', false );

基本functions.php設定


// メインコンテンツの幅を指定
if ( ! isset( $content_width ) ) $content_width = 1000;

/*headの抑制*/
/* DNSプリフェッチ設定の削除 */
add_filter( 'emoji_svg_url', '__return_false' );

/* 絵文字削除 */
remove_action( 'wp_head',             'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles',     'print_emoji_styles' );
remove_action( 'admin_print_styles',  'print_emoji_styles' );

//ヘッダーのワードプレスのバージョンを消す
remove_action('wp_head','wp_generator');

/* wp-json削除 */
remove_action('wp_head','rest_output_link_wp_head');
remove_action('wp_head','wp_oembed_add_discovery_links');

/* 外部投稿ツール設定削除 */
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'rsd_link' );

//コメントフォームのHTMLタグの表示を消す
add_filter("comment_form_defaults","my_special_comment_after");
function my_special_comment_after($args){
$args['comment_notes_after'] = '';
return $args;
}

//コメントのURLとメールアドレス入力を消す。
add_filter('comment_form_default_fields', 'mytheme_remove_url');
function mytheme_remove_url($arg) {
$arg['url'] = '';
$arg['email'] = '';
return $arg;
}

add_filter( "comment_form_defaults", "my_comment_notes_before");
function my_comment_notes_before( $defaults){
$defaults['comment_notes_before'] = '';
return $defaults;
}

//グローバルナビ作成作成
add_action( 'after_setup_theme', function(){
	register_nav_menus( array(
	// 例 'メニューの位置を示す固有名称' => 'このメニューの位置の名称'
	'global-nav' => 'グローバルメニュー',
	'header-nav' => 'ヘッダーナビ',
	) );
} );
function disable_default_gallery_style() {
return false;
}

//投稿のビジュアルにCSSを適用する。
add_editor_style();

//読み込みたくないCSS
function dequeue_plugins_style() {
	wp_dequeue_style( 'biz-cal-style' );
}
add_action( 'wp_enqueue_scripts', 'dequeue_plugins_style', 100 );



//プラグイン自動更新停止
add_filter( 'auto_update_plugin', '__return_false' );
//Wordpressテーマの更新停止
add_filter( 'auto_update_theme', '__return_false' );



/*アイキャッチ対応 */
function setup_theme() {
    add_theme_support('post-thumbnails');
}
add_action('after_setup_theme', 'setup_theme');


//archivepageの余計な文字を削除
  add_filter( 'get_the_archive_title', function($title){
	if(is_category()){ // カテゴリーページ
		$title = single_cat_title('', false);
	} elseif(is_tag()){ // タグページ
		$title = single_tag_title('', false);
	} elseif(is_tax()){ // タクソノミーページ
		$title = single_term_title('', false);
	} elseif(is_post_type_archive()){ //カスタム投稿タイプアーカイブページ
		$title = post_type_archive_title('', false);
	}
    return $title;
});