WordPressのfunctions.phpに使いがちなコードまとめ

<?php
// ***** 最初に記述する。あると安心
if ( !defined( 'ABSPATH' ) ) {
exit;
}

// ***** ヘッダーを綺麗に
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'index_rel_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_wp_head', 10, 0 );
remove_action( 'wp_head', 'wp_generator' );

// ***** セルフピンバック禁止
function no_self_ping( &$links ) {
$home = home_url();
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );

// ***** 404エラーの場合トップページへ移動
function is404_redirect_home() {
if( is_404() ){
wp_safe_redirect( home_url( '/' ) );
exit();
}
}
add_action( 'template_redirect', 'is404_redirect_home' );

// ***** クイックタグ
if (!function_exists('st_add_orignal_quicktags')) {
function st_add_orignal_quicktags() {
if ( wp_script_is( 'quicktags' ) ) { ?>
<script type="text/javascript">
QTags.addButton('ed_h2', 'h2', '<h2>', '</h2>');
QTags.addButton('ed_h3', 'h3', '<h3>', '</h3>');
QTags.addButton('ed_h4', 'h4', '<h4>', '</h4>');
QTags.addButton('ed_p', 'P', '<p>', '</p>');
</script>
<?php
}
}
}
add_action('admin_print_footer_scripts', 'st_add_orignal_quicktags');

// ***** 絵文字機能を停止
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
}
add_action( 'init', 'disable_emojis' );

// ***** カスタムフィールドしか無い場合、本文入力欄を消す
function remove_post_supports() {
remove_post_type_support( 'slide', 'editor' );
}
add_action( 'init', 'remove_post_supports' );

// ***** アイキャッチ画像を有効にする
add_theme_support('post-thumbnails');
set_post_thumbnail_size( 335, 300, true );

//自動整形を無効にする投稿タイプを記述 =固定ページ
$arr_types = array('page');
$post_type = get_post_type( $post->ID );
if (in_array($post_type, $arr_types)){
$remove_filter = true;
}

//投稿ページ以外の自動整形を無効にしたければ
if (!is_single()){
$remove_filter = true;
}

\よかったら使ってね/

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)