新規テーマ作成するときにやること 新規テーマに必要なもの

新規テーマに必要なもの

下記フォルダに作成
wp-content/themes/newtheme/

  • functions.php
  • style.php
  • screenshot.png
  • index.phpなどテーマファイル

functions.php の設置

/*** ヘッダータグの消去 ***/
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
remove_action('wp_head', 'feed_links_extra',3,0);
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator'); // バージョン表示削除
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'parent_post_rel_link');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'rel_canonical');

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


/* アイキャッチ画像 */
add_theme_support( 'post-thumbnails' );

// オリジナルの大きさのサムネイルを生成したい場合(the_post_thumbnail('my_thumbnail')で利用)
// add_image_size( 'my_thumbnail', 200, 200, true );


/* 記事本文のpタグbrタグの自動整形を停止する */
// remove_filter('the_content', 'wpautop');
/* 抜粋のpタグbrタグの自動整形を停止する */
// remove_filter('the_excerpt', 'wpautop');

// 管理画面を強制SSL
define('FORCE_SSL_ADMIN', true);

カスタム投稿タイプ

add_action( 'init', 'create_post_type' );
function create_post_type() {
  register_post_type( 'example',
    array(
      'labels' => array(
        'name' => __( 'テスト' ),
        'singular_name' => __( 'テスト' )
      ),
      'public' => true,
      'menu_position' =>3,
    )
  );
}

ウィジェット

 /* ウィジェット */
register_sidebar(array(
'name'=>'サイドバー',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="sidebar-title">',
'after_title' => '</div>',
));

参考サイト
http://kachibito.net/wordpress/add-my-functions.html
http://netaone.com/wp/functions-php/

ヴィジュアルエディタ

/* ヴィジュアルエディタに項目追加 */
function ilc_mce_buttons($buttons){
array_push($buttons, "backcolor", "copy", "cut", "paste", "fontsizeselect", "cleanup");
return $buttons;
}
add_filter("mce_buttons", "ilc_mce_buttons");

/* ヴィジュアルエディタの段落を、h3,h4,h5のみにする */
function custom_editor_settings( $initArray ){
    // WordPress3くらい
    //$initArray['theme_advanced_blockformats'] = 'p,address,pre,code,h3,h4,h5,h6';
    // WordPress4から
    $initArray['block_formats'] = "見出し3=h3; 見出し4=h4; 見出し5=h5;";
    return $initArray;
}
add_filter( 'tiny_mce_before_init', 'custom_editor_settings' );

style.php の設置

最低限必要なコード

@charset "utf-8";

/*
Theme Name: Test
Description: PC、タブレット、スマートフォンと見ているデバイスに自動最適化されるレスポンシブデザインに対応したミニマルでシンプルな公式サイトタイプのWordPressテーマです。トップページにはスライドショーとサムネイルギャラリーを配置しました。とびきりの写真やイラストでオリジナリティ溢れるトップページにしてください。ロゴ、メニュー、スライドショー、ウィジェットが、管理画面から簡単にカスタマイズできますので、HTMLの知識が無くてもオリジナルサイトが作れます。
Version: 1.0
Author: K
Theme URI: http://devweb.work
Author URI: http://devweb.work
*/

導入プラグイン

パンくず

Prime Strategy Bread Crumb
http://www.warna.info/archives/1310/#parameters

<?php
if (function_exists('bcn_display')) bcn_display;
?>

classやidの付け方については、公式サイトに記載されている
https://mtekk.us/code/breadcrumb-navxt/

タイトルとURLをコピーしました