Skip to content

Instantly share code, notes, and snippets.

@ma2i
ma2i / function.php
Created August 3, 2020 11:32
投稿ページのスラッグ名 「sample」 のページのみ適用されるCSSを設定する方法
/* 「custom-sample.css」 は、子テーマの「sango-theme-poripu」直下にアップする */
function add_custom_styles_sample() {
if ( is_single('sample') ) {
wp_enqueue_style('add_custom_styles_sample',get_stylesheet_directory_uri() . '/custom-sample.css');
}
}
add_action( 'wp_enqueue_scripts', 'add_custom_styles_sample' );
/* 目次に戻るボタンの表示 */
add_filter('the_content', function( $content ){
if ( is_singular() && strpos( $content, ' id="ez-toc-container' ) !== false ){
//挿入するHTML
$back_toc = '<div class="back-toc" style="font-weight:bold;font-size:15px;"><a href="#ez-toc-container"><i class="fa fa-arrow-up" aria-hidden="true"></i> 目次に戻る</a></div>';
$count = 0;
$content = preg_replace_callback('/<h2 *[^>]*>/i', function( $m ) use (&$count, $back_toc) {
$count++;
if( $count == 1 ) {
@ma2i
ma2i / SANGO.css
Created February 7, 2020 04:25
SANGO
/* ヘッダーナビ */
.header{
box-shadow:none;
}
/* WordPressにログイン中、公開ページを見ると、画面上部に固定されるメニューの変更 */
@ma2i
ma2i / Google-Analytics-For-WordPress.php
Created December 25, 2019 08:06
WordPressにログイン中のユーザーのログは除外する
<!-- Google Analytics -->
<?php if ( !(is_user_logged_in()) ) : ?>
ここにアナリティクスのトラッキングコードを挿入
<?php endif; ?>
@ma2i
ma2i / child-functions.php
Last active September 20, 2019 02:38
【WordPress】特定のカテゴリーをウィジェットのカテゴリー覧で非表示にする(子テーマのfunctions.phpに記述)
/* 子テーマのfunctions.php に記述 */
/* 特定のカテゴリーをウィジェットのカテゴリーの一覧で非表示(子テーマのfunctions.phpに記述) */
function exclude_widget_categories($args){
$args['exclude'] = '27';
return $args;
}
add_filter( 'widget_categories_args', 'exclude_widget_categories');
@ma2i
ma2i / admin-style.css
Created September 20, 2019 02:29
【WordPress】管理画面でブログ名やユーザ名を見えにくくする
/* 子テーマに「admin-style.css」というファイルを新規追加 */
/* WordPressの管理画面のスタイルを変更 */
#wpadminbar a.ab-item{
color : #23282d !important;
}
#wpadminbar a.ab-item img.avatar{
display: none !important;
}
@ma2i
ma2i / Bootstrap-Responsive-Breakpoints.css
Created September 20, 2019 02:25
レスポンシブ対応(Bootstrap4のブレークポイント)
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }
// Extra large devices (large desktops, 1200px and up)
@ma2i
ma2i / functions.php
Created September 20, 2019 02:24
【WordPress】特定カテゴリの記事をブログトップの新着記事一覧で表示させない
/* 特定のカテゴリの除外
function exclude_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '-8,-9' );//マイナスをつけてカテゴリIDを除外する
}
}
add_action( 'pre_get_posts', 'exclude_category' );
@ma2i
ma2i / bootstrap-flexbox.css
Created September 20, 2019 02:23
Bootstrap(FlexBox)一部
/* Flex */
.d-flex{
display : flex;
}
.d-inline-flex{
display : inline-flex;
}
/* Direction */
.flex-row{
@ma2i
ma2i / functions.php
Created September 20, 2019 02:22
【WordPress】見出しを画面上部に固定表示する方法
/*
① プラグイン「Easy Table of Contents」 は入れておく
② ページのスクロールと連動し、今読んでいるコンテンツの見出しが画面上部に固定表示される
*/
//上部固定の見出しラベルを作るよ
function kjk_fixed_headline_script() {
?>