Skip to content

Instantly share code, notes, and snippets.

@gatespace
gatespace / page-scroll.js
Last active May 26, 2017 09:51
jQuery ページ内リンクと先頭に戻るスムーズスクロール ref: http://qiita.com/gatespace/items/e5b5d441c5170e60f2e9
(function($){
/*
* jQuery page scroll
*/
var topBtn = $('#page-top'); // 先頭に戻るボタンの入るDOM
var topHash = '#_top'; // 先頭に戻るボタンのhrefの中身
var viewPos = 100; // 先頭に戻るボタンが表示され始める位置
@gatespace
gatespace / masthead-scroll.js
Last active August 27, 2018 02:27
スクロールするとヘッダーがふわっと固定されるパターン ref: https://qiita.com/gatespace/items/a9fa68dacc2e30f7f219
(function($) {
$(window).on('load resize', function(){
// masthead scroll
var header = $('#header-nav'); // fixed DOM
var addclass = 'scrolled'; // add css class
var offset = header.offset();
var scrollY = offset.top; // scroll
$(window).scroll(function() {
if ($(window).scrollTop() > scrollY) {
@gatespace
gatespace / my-get-posts.php
Last active November 18, 2024 16:16
WordPress テーマ(プラグイン)開発オレオレsnippet集+便利なサービス ref: https://qiita.com/gatespace/items/324a037dd241ee908dd8
<?php
$args = array(
'posts_per_page' => 5,
'offset' => 0,
'category' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
@gatespace
gatespace / my-jetpack-publicize-message.php
Last active February 10, 2017 06:42
WordPress Jetpackのパプリサイズ共有で常にハッシュタグなどを付けたい ref: http://qiita.com/gatespace/items/3306a77f045c27bda114
<?php
/*
Plugin Name: My Jetpack Publicize Message
Plugin URI:
Description:
Version: 0.1.0
Author: Your Name
Author URI:
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@gatespace
gatespace / my-must-login-pages.php
Last active February 10, 2017 07:31
WordPress で特定のカテゴリーの記事はログインしないと見られないけど記事一覧などでは特定の文言に置き換えるパターン ref: http://qiita.com/gatespace/items/d4ada939b458e8b87834
<?php
function my_must_login_pages() {
if ( is_feed() ) // フィードの時は除外
return;
$loginflg = false; // 条件が増えてもいいようにフラグを作っておく。 デフォルトはfalse
if ( has_term( 'private', 'category' ) ) {
$loginflg = true;
}
@gatespace
gatespace / functions.php
Last active February 10, 2017 07:31
WordPress Jetpack の Share 及び Like ボタン群を任意の場所に移動(ざっくり翻訳) ref: http://qiita.com/gatespace/items/93fcf641e99c2a185636
function jptweak_remove_share() {
remove_filter( 'the_content', 'sharing_display',19 );
remove_filter( 'the_excerpt', 'sharing_display',19 );
if ( class_exists( 'Jetpack_Likes' ) ) {
remove_filter( 'the_content', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 );
}
}
add_action( 'loop_start', 'jptweak_remove_share' );
@gatespace
gatespace / mytheme_post_edit_required.php
Last active February 10, 2017 07:31
WordPressの投稿作成画面で空欄ならアラートを出す ref: http://qiita.com/gatespace/items/e13b4537282386c6ff3f
<?php
add_action( 'admin_head-post-new.php', 'mytheme_post_edit_required' ); // 新規投稿画面でフック
add_action( 'admin_head-post.php', 'mytheme_post_edit_required' ); // 投稿編集画面でフック
function mytheme_post_edit_required() {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
if( 'post' == $('#post_type').val() || 'page' == $('#post_type').val() ){ // post_type 判定。例は投稿と固定ページ。カスタム投稿タイプは適宜追加
$("#post").submit(function(e){ // 更新あるいは下書き保存を押したとき
if('' == $('#title').val()) { // タイトル欄の場合
@gatespace
gatespace / file0.php
Last active February 10, 2017 07:31
Contact Form 7 で YubinBango を使う ref: http://qiita.com/gatespace/items/e30f4749d089fd67184f
wp_enqueue_script( 'yubinbango', 'https://yubinbango.github.io/yubinbango/yubinbango.js', array(), null, true );
@gatespace
gatespace / file0.php
Last active February 10, 2017 07:32
WordPress JetpackのOGPタグのデフォルト画像とアーカイブ系での出力 ref: http://qiita.com/gatespace/items/083b8e47b1e4504720ea
function my_open_graph_image_default( $image ) {
$image = get_stylesheet_directory_uri() . '/images/my_open_graph_image_default.png';
return $image;
}
add_filter( 'jetpack_open_graph_image_default', 'my_open_graph_image_default' );
@gatespace
gatespace / file0.php
Last active February 10, 2017 07:32
WordPress JetpackのMarkdownとパブリサイズ共有をカスタム投稿タイプで使う ref: http://qiita.com/gatespace/items/d8fef357d3a074b5a916
<?php
// Register Custom Post Type
function my_custom_post_type() {
$labels = array(
'name' => _x( 'Products', 'Post Type General Name', 'text_domain' ),
);
$args = array(
'label' => __( 'product', 'text_domain' ),
'supports' => array( 'title', 'editor', 'publicize', 'wpcom-markdown' ),
);