Skip to content

Instantly share code, notes, and snippets.

View hissy's full-sized avatar
💭
😄

Takuro Hishikawa hissy

💭
😄
View GitHub Profile
@hissy
hissy / gist:2886468
Last active October 5, 2015 22:18
#WordPress Is current page? by page path
<?php
/*
Usage:
if ( is_current_page_by_path( '/hoge' ) ) {
// is hoge page
} else {
// is not hoge page
}
*/
@hissy
hissy / gist:2921625
Created June 13, 2012 03:21
check the post is recently posted #WordPress
/**
* Usage: if ( is_new() ) : echo 'NEW!'; endif;
* you can check if the post was posted within 30 days.
*/
function is_new($day=30,$post=null){
$term = $day * 24 * 60 * 60;
$post = get_post($post);
if ( !$post || is_wp_error( $post ) )
return false;
$the_time = $post->post_date;
@hissy
hissy / gist:2921663
Last active October 6, 2015 02:38
check the page is a SubPage #WordPress
<?php
/*
* Usage
* if ( is_subpage( get_the_ID() ) :
* // subpage
* else:
* // not a subpage
* endif;
*/
function is_subpage( $post ) {
@hissy
hissy / gist:2921668
Last active October 6, 2015 02:38
check the post has children #WordPress
<?php
/**
* Usage
* if ( has_children( get_the_ID() ) ) :
* // this post has children
* else:
* // this post has no children
* endif;
*/
function has_children( $post ) {
@hissy
hissy / gist:3180603
Created July 26, 2012 06:38
Get Date String Japanese Style
function getDateStringI18n(string){
var parts = String(string).split(/[- :]/);
var newString = parts[0] + '年' + parts[1] + '月' + parts[2] + '日';
return newString;
}
@hissy
hissy / gist:3613306
Last active June 26, 2023 22:56
[WordPress] change next / previous post link ordering
<?php
/**
* Customize Adjacent Post Link Order
*/
function my_custom_adjacent_post_where($sql) {
if ( !is_main_query() || !is_singular() )
return $sql;
$the_post = get_post( get_the_ID() );
$patterns = array();
@hissy
hissy / gist:3662674
Created September 7, 2012 02:46
[WordPress] [Facebook plugin] fix: Facebook locale does not set to "ja_JP" when using Japanese package
// please paste it in your functions.php
function filter_facebook_locale($locale){
$wp_locale = get_locale();
if ( $wp_locale = 'ja' ) $locale = 'ja_JP';
return $locale;
}
add_filter('fb_locale','filter_facebook_locale');
@hissy
hissy / gist:3775883
Created September 24, 2012 13:11
[WordPress] Custom Post Type Support with CMS Page Order Plugin
/**
* Custom Post Type Support with CMS Page Order Plugin
* http://wordpress.org/extend/plugins/cms-page-order/
*/
function my_filter_cmspageorder($post_types){
$post_types[] = 'custom'; // add 'custom' post type
return $post_types;
}
add_filter('cmspo_post_types','my_filter_cmspageorder');
@hissy
hissy / gist:3780493
Created September 25, 2012 07:45
[WordPress] fixes admin menu order conflict
<?php
add_action( 'admin_menu', 'admin_menu_order_hack', 9); // 9 is the priority contact form 7 applies.
function admin_menu_order_hack() {
global $_wp_last_object_menu;
$_wp_last_object_menu++;
}
@hissy
hissy / gist:4116825
Last active October 13, 2015 01:18
[WordPress] Override Loading Template
<?php
/**
* This is a example: force to use index.php at tag archive
*/
function my_template_include($template){
if ( is_tag() ) {
$template = get_index_template();
}
return $template;
}