This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//ogpとtwitter card画像が登録されていない場合はデフォルトに登録した画像で上書き | |
function override_ogp_img($img){ | |
$og_image_flag = true; | |
if ( is_single()) { | |
$post_id = get_the_id(); | |
$og_image = get_post_meta( $post_id, '_yoast_wpseo_opengraph-image', true ); // yoast 取得 | |
if ( empty( $og_image ) ) { // yoastの投稿の設定がない | |
$og_image_flag = false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Exclude Algolia search | |
Plugin URI: | |
Description: Algolia の検索結果から除外するフラグを追加。WP Search with Algolia プラグインが必要。 | |
Version: 0.1 | |
Author: gatespace | |
Author URI: https://gatespace.jp | |
License: GPLv2 or later | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'get_pagenum_link', 'my_search_paginate_links' ); | |
add_filter( 'paginate_links', 'my_search_paginate_links' ); | |
function my_search_paginate_links( $link ) { | |
if ( is_search() ) { | |
$pattern = '/page\/(\d+)\/\?s=([^\/]+)/i'; | |
if ( preg_match( $pattern, $link ) ) { | |
$link = preg_replace( $pattern, '?s=$2&paged=$1', $link ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'manage_posts_columns' , 'add_publish_date_columns' ); | |
function add_publish_date_columns( $columns ) { | |
$new_columns = array(); | |
foreach ( $columns as $column_name => $column_display_name ) { | |
if ( $column_name == 'date' ) { | |
$new_columns['publish_date'] = '掲載日時'; | |
} | |
$new_columns[ $column_name ] = $column_display_name; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ wp scaffold _s <slug> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'wpbs_draft_to_publish_update_post', 'my_wpbs_draft_to_publish_update_post', 10, 1 ); | |
function my_wpbs_draft_to_publish_update_post( $new ) { | |
// 元記事の更新日時をブランチ記事の公開日時にする | |
$new['post_modified'] = $new['post_date']; | |
$new['post_modified_gmt'] = $new['post_date_gmt']; | |
// 元記事の公開日時は変更しない | |
$old_id = $new['ID']; | |
$old_post = get_post( $old_id ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ids = sirp_get_related_posts_id(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// get_terms でタグに所属する投稿が指定した件数より少なかったら表示しない | |
add_filter( 'get_terms', 'my_get_terms', 10, 4 ); | |
function my_get_terms( $terms, $taxonomies, $args, $term_query ) { | |
if ( is_admin() ) { // 管理画面だったら何もしない | |
return $terms; | |
} | |
if ( $taxonomies[0] != 'post_tag' ) { // 条件分岐はよしなに | |
return $terms; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'template_redirect', 'tag_archive_template_redirect' ); | |
function tag_archive_template_redirect() { | |
if ( ! is_tag() ) { // タグアーカイブ以外は何もしない | |
return; | |
} | |
$queried = get_queried_object(); | |
if ( $queried->count < 6 ) { // 総記事数が5件以下なら |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function numeric_term_link( $url, $term, $taxonomy ) { | |
global $wp_rewrite; | |
// post_tag only | |
if ( $taxonomy == 'post_tag' ) { | |
if ( $wp_rewrite->using_permalinks() ) { | |
$permastruct = $wp_rewrite->get_extra_permastruct( 'post_tag' ); | |
$permastruct = str_replace( '%post_tag%', $term->term_id, $permastruct ); | |
$url = home_url( user_trailingslashit( $permastruct, 'tag' ) ); |
NewerOlder