wordpressでよく使うやつ

functipon.php


//background
add_theme_support('custom-background');

// widgetのtext ショートカット
add_filter('widget_text', 'do_shortcode');

// ヘッダー
add_theme_support( 'custom-header' );

//タイトルからキャッチフレーズを削除する
function remove_tagline($title)
{
    if (isset($title['tagline'])) {
        unset($title['tagline']);
    }
    return $title;
}
  add_filter('document_title_parts', 'remove_tagline');

//youtubeをレスポンシブ
function iframe_in_div($the_content)
{
    if (is_singular()) {
        $the_content = preg_replace('/<iframe/i', '<div class="youtube"><iframe', $the_content);
        $the_content = preg_replace('/<\/iframe>/i', '</iframe></div>', $the_content);
    }
    return $the_content;
}
add_filter('the_content', 'iframe_in_div');

// jetpack ギャラリー横幅
if (! isset($content_width)) {
    $content_width = 1140;
}

// jetpack コメント欄削除
function tweakjp_rm_comments_att($open, $post_id)
{
    $post = get_post($post_id);
    if ($post->post_type == 'attachment') {
        return false;
    }
    return $open;
}
add_filter('comments_open', 'tweakjp_rm_comments_att', 10, 2);

// bs4navwalker-bootstrap・navbarドロップダウン
    require_once('views/bs4navwalker.php');

// カスタムHTMLウィジェットでPHP
function widget_text_exec_php($widget_text)
{
    if (strpos($widget_text, '<' . '?') !== false) {
        ob_start();
        eval('?>' . $widget_text);
        $widget_text = ob_get_contents();
        ob_end_clean();
    }
    return $widget_text;
}
add_filter('widget_text', 'widget_text_exec_php', 99);

 // ページャー
 function bootstrap_pagination(\WP_Query $wp_query = null, $echo = true)
 {
     if (null === $wp_query) {
         global $wp_query;
     }
     $pages = paginate_links(
         [
             'base'         => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
             'format'       => '?paged=%#%',
             'current'      => max(1, get_query_var('paged')),
             'total'        => $wp_query->max_num_pages,
             'type'         => 'array',
             'show_all'     => false,
             'end_size'     => 1,
             'mid_size'     => 1,
             'prev_next'    => true,
             'prev_text'    => __('« Prev'),
             'next_text'    => __('Next »'),
             'add_args'     => false,
             'add_fragment' => ''
         ]
     );
     if (is_array($pages)) {
         //$paged = ( get_query_var( 'paged' ) == 0 ) ? 1 : get_query_var( 'paged' );
         $pagination = '<div class="pagination"><ul class="pagination">';
         foreach ($pages as $page) {
             $pagination .= '<li class="page-item' . (strpos($page, 'current') !== false ? ' active' : '') . '"> ' . str_replace('page-numbers', 'page-link', $page) . '</li>';
         }
         $pagination .= '</ul></div>';
         if ($echo) {
             echo $pagination;
         } else {
             return $pagination;
         }
     }
     return null;
 }
 
 // Jetpack's Infinite Scroll
 function infinite_scroll_render()
 {
     while (have_posts()) : the_post();
     get_template_part('templates/partials/content', get_post_type() != 'post' ? get_post_type() : get_post_format());
     //get_template_part('templates/content');
     endwhile;
 }
  function infinite_scroll_init()
  {
      add_theme_support('infinite-scroll', array(
     //   'type'           => 'scroll',
        'footer'         => false,
        'footer_widgets' => false,
        'container'      => 'main', // 投稿を追加するHTML要素のIDを指定
        'wrapper'        => false,
        'render'         => 'infinite_scroll_render',
        'posts_per_page' => false,
    ));
  }
  add_action('init', __NAMESPACE__ . '\\infinite_scroll_init');

// infinite_scroll 文字変更
  function filter_jetpack_infinite_scroll_js_settings($settings)
  {
      $settings['text'] = __('Load more <i class="fas fa-caret-down"></i>', 'l18n');
      return $settings;
  }
add_filter('infinite_scroll_js_settings', 'filter_jetpack_infinite_scroll_js_settings');

// jetpack.cssの読み込みを早く
add_filter('jetpack_implode_frontend_css', '__return_false', 99);

// gutenberg コンテンツ幅変更
add_action('admin_head', function () {
    echo '<style>.wp-block{max-width: 1200px !important}</style>'."\n";
});

// reCAPTCHAを使っているページにだけロゴを表示
add_action('wp_enqueue_scripts', function () {
    if (is_page('contact')) {
        return;
    }
    wp_deregister_script('google-recaptcha');
});

css

/* navbar */

.navbar-toggler .navbar-toggler-icon {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(65,105,225,1)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E");
}

img {
  max-width: 100%;
  height: auto;
}

@-webkit-keyframes flash {
  0% {
    opacity: 0.4;
  }
  100% {
    opacity: 1;
  }
}

@keyframes flash {
  0% {
    opacity: 0.4;
  }
  100% {
    opacity: 1;
  }
}
/* tittle */

.tt-boder-primary {
  border-bottom: 1px solid $blue;
  border-left: 10px solid $blue;
  padding: 7px;
}

.tt-boder-secondary {
  border-bottom: 1px solid $gray-800;
  border-left: 10px solid $gray-800;
  padding: 7px;
}
/* loding */

.loader-bg {
  background: #fff;
  height: 100%;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  img {
    background: #fff;
    position: fixed;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    z-index: 200000;
  }
}
/* woo */

.add_to_cart_button {
  visibility: hidden;
}

.price {
  visibility: hidden;
}
/* youtube */

.youtube {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
}

.youtube iframe {
  position: absolute;
  top: 0;
  right: 0;
  width: 100% !important;
  height: 100% !important;
}
/* page-top */

.page-top {
  position: fixed;
  bottom: 60px;
  right: 10px;
  font-size: 16px;
}
/* pager */

.pager {
  text-align: center;
}

a.page-numbers {
  background: rgba(0, 0, 0, 0.02);
  border: solid 1px rgba(0, 0, 0, 0.1);
  border-radius: 5px;
  padding: 5px 8px;
  margin: 0 2px;
}

.pager .current {
  background: rgba(0, 0, 0, 0.02);
  border: solid 1px rgba(0, 0, 0, 0.1);
  border-radius: 5px;
  padding: 5px 8px;
  margin: 0 2px;
  background-color: rgba(100, 100, 100, 1);
  color: rgba(255, 255, 255, 1);
}
/* back to top */

#page-top {
  position: fixed;
  bottom: 60px;
  right: 10px;
  font-size: 16px;
}
/* infinite-scroll */

#infinite-handle span {
  background: $blue;
  color: #eee;
  cursor: pointer;
  font-size: 18px;
  padding: 6px 24px;
  border-radius: 5px;
}
/* slick */

.slider-container {
  position: relative;
}

.slider {
  display: none;
  margin: 0;
  overflow: visible;
  &.slick-initialized {
    display: block;
  }
}

.slider-arrow {
  position: absolute;
  top: 50%;
  height: 36px;
  margin-top: -18px;
  color: $blue;
  line-height: 36px;
  cursor: pointer;
  z-index: 10;
}

.slider-prev {
  left: 20px;
}

.slider-next {
  right: 20px;
}

.slick-slide {
  padding: 0;
  color: #fff;
  text-align: center;
  font-size: 1.1em;
  outline: 0;
  background-color: #fff;
} //アドセンス検索
.gsc-input {
  margin: 0;
}

.woocommerce-additional-fields .woocommerce-input-wrapper {
  width: 100%;
} // Block Reveal Effects
.breffects {
  opacity: 0;
}

.blockn {
  position: relative;
  overflow: hidden;
  opacity: 1;
  .reveal {
    margin: 0;
    padding: 0;
    animation: fadeIn 0.6s 0.6s;
    animation-fill-mode: backwards;
  }
  &::after {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: $blue;
    transform: translateX(-100%);
    animation: secondaryImageOverlayIn 0.6s 0s,
      secondaryImageOverlayOut 0.6s 0.6s;
    animation-fill-mode: both;
  }
}

@keyframes fadeIn {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

@keyframes secondaryImageOverlayIn {
  0% {
    width: 0;
  }
  100% {
    width: 100%;
  }
}

@keyframes secondaryImageOverlayOut {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(100%);
  }
}

@media screen and (max-width: 600px) {
  .img-slider {
    width: 100%;
    height: 240px;
    object-fit: cover;
  }
}


jQuery

// page top
jQuery(function () {
  var pageTop = jQuery(".page-top");
  pageTop.hide();
  jQuery(window).scroll(function () {
    if (jQuery(this).scrollTop() > 400) {
      pageTop.fadeIn();
    } else {
      pageTop.fadeOut();
    }
  });
  pageTop.click(function () {
    jQuery("body,html").animate(
      {
        scrollTop: 0,
      },
      900
    );
    return false;
  });

  // start fade
  jQuery(window).on("load", function () {
    jQuery(".loader-bg").hide();
  });

  // bottomenu
  var menuHeight = jQuery("#bottomenu").height();
  var navPos = 10;
  jQuery(window).scroll(function () {
    var Pos = jQuery(this).scrollTop();
    if (Pos > navPos) {
      if (jQuery(window).scrollTop() >= 100) {
        jQuery("#bottomenu").css("bottom", "-" + menuHeight + "px");
      }
    } else {
      jQuery("#bottomenu").css("bottom", "0px");
    }
    navPos = Pos;
  });
  // --navbar fade--
  jQuery(window).on("load", function () {
    var offset = jQuery(".navbar").offset();

    jQuery(window).scroll(function () {
      if (jQuery(window).scrollTop() > offset.top) {
        jQuery(".navbar").addClass("fixed-top");
      } else {
        jQuery(".navbar").removeClass("fixed-top");
      }
    });
  });

  // current_page_item
  jQuery(
    ".current_page_item a, .current-menu-item a, .current-cat a, .current-menu-parent a"
  ).addClass("text-dark");
});

jQuery(document).ready(function () {
  console.log("ready");
  var EffectH = 100;
  jQuery(window).on("scroll load", function () {
    var scTop = jQuery(this).scrollTop();
    var scBottom = scTop + jQuery(this).height();
    var effectPos = scBottom - EffectH;
    jQuery(".breffects").each(function () {
      var thisPos = jQuery(this).offset().top;
      if (thisPos < effectPos) {
        // .js-scrollという要素が可視範囲に入ったら
        jQuery
          .when(
            // .js-scrollにshowというclassを付与
            jQuery(this).addClass("")
          )
          .done(function () {
            //  その後、0.5秒遅らせて.js-scrollにdoneというclassを付与
            jQuery(this)
              .delay(0)
              .queue(function () {
                jQuery(this).addClass("blockn");
              });
          });
      }
    });
  });
});