STINGERは、そもそもネット上の多くの有益な情報を集めて制作したWordPressテーマです。ここでは既に実装済みの内容と、参考サイトを掲載いたします。重複したプラグインやコードはエラーの原因となりますのでぜひ、CHECKして下さい。
また、不要だと思う機能はどうぞ、削除して下さい。
photo credit: slworking2 via photopin cc
functions.php
jQueryの読み込み
1 2 3 4 5 6 7 8 9 10 |
function register_user_script() { if (!is_admin()) { $script_directory = get_template_directory_uri(); wp_deregister_script('jquery'); wp_enqueue_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js'); } } add_action('init','register_user_script'); |
functions.phpでjQueryを読み込んでますので色々上手くいかない人は、コレを外して別途読み込んでください。
日本語スラッグを数字に変更
1 2 3 4 5 6 7 8 |
//WordPress の投稿スラッグを自動的に生成する function auto_post_slug( $slug, $post_ID, $post_status, $post_type ) { if ( preg_match( '/(%[0-9a-f]{2})+/', $slug ) ) { $slug = utf8_uri_encode( $post_type ) . '-' . $post_ID; } return $slug; } add_filter( 'wp_unique_post_slug', 'auto_post_slug', 10, 4 ); |
日本語パーマリンクは拡散時にも非常に長いURLとなり、エラーの原因になったりします。なのでSTINGERでは英数字に変換しています。日本語URLを使用したい人はコレを削除して下さい。
Simple Colors
WordPress の投稿スラッグを自動的に生成する
エディタスタイル
1 2 3 4 5 6 7 8 |
//エディタスタイル add_theme_support('editor-style'); add_editor_style('editor-style.css'); function custom_editor_settings( $initArray ){ $initArray['body_class'] = 'editor-area'; return $initArray; } add_filter( 'tiny_mce_before_init', 'custom_editor_settings' ); |
管理画面のCSSを設定できます。
ページャー機能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
//ページャー機能 function pagination($pages = '', $range = 4) { $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == '') { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>"; if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link (1)."'>« First</a>"; if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹ Previous</a>"; for ($i=1; $i <= $pages; $i++) { if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) { echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link ($i)."' class=\"inactive\">".$i."</a>"; } } if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next ›</a>"; if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last »</a>"; echo "</div>\n"; } } |
Colis
WordPressにプラグイン無しでページネーションを設置する方法
ヘッダーの掃除
1 2 3 4 5 6 7 8 9 10 |
//ヘッダーを綺麗に 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' ); |
「Header Creaner」を使用したい人はこれを削除した方がいいかも。(※未検証)
オウガログ
プラグインを使わないでヘッダーを綺麗に整頓する
moreリンクの#moreを消す
1 2 3 4 5 6 |
//moreリンク function custom_content_more_link( $output ) { $output = preg_replace('/#more-[\d]+/i', '', $output ); return $output; } add_filter( 'the_content_more_link', 'custom_content_more_link' ); |
セルフピンバックの禁止
1 2 3 4 5 6 7 8 |
//セルフピンバック禁止 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' ); |
各ウィジェットの追加
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
//ウイジェット追加 if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(4) ) register_sidebars(1, array( 'name'=>'サイドバー1', 'before_widget' => '<ul><li>', 'after_widget' => '</li></ul>', 'before_title' => '<h4 class="menu_underh2">', 'after_title' => '</h4>', )); register_sidebars(1, array( 'name'=>'スクロール広告用', 'before_widget' => '<ul><li>', 'after_widget' => '</li></ul>', 'before_title' => '<h4 class="menu_underh2" style="text-align:left;">', 'after_title' => '</h4>', )); register_sidebars(1, array( 'name'=>'Googleアドセンス用', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h4 style="display:none">', 'after_title' => '</h4>', )); register_sidebars(1, array( 'name'=>'Googleアドセンスのスマホ用width300', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h4 style="display:none">', 'after_title' => '</h4>', )); |
更新日の追加
1 2 3 4 5 6 7 8 9 10 11 12 |
//更新日の追加 function get_mtime($format) { $mtime = get_the_modified_time('Ymd'); $ptime = get_the_time('Ymd'); if ($ptime > $mtime) { return get_the_time($format); } elseif ($ptime === $mtime) { return null; } else { return get_the_modified_time($format); } } |
OBRIGADO! ARIGATO!
WordPress 記事の見直しと最終更新日の表記。それを Google に伝える
テーマの中のコードに関してはまた後日。。