This file contains 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
// By @coderitual | |
// https://twitter.com/coderitual/status/1112297299307384833 | |
// Remove any duplicates from an array of primitives. | |
const unique = [...new Set(arr)] | |
// Sleep in async functions. Use: await sleep(2000). | |
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms))); | |
// Type this in your code to break chrome debugger in that line. |
This file contains 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 | |
//https://pippinsplugins.com/retrieve-attachment-id-from-image-url/ | |
function pippin_get_image_id($image_url) { | |
global $wpdb; | |
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url )); | |
return $attachment[0]; | |
} | |
?> |
This file contains 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('page_attributes_dropdown_pages_args', 'add_private_draft'); | |
function add_private_draft($args) { | |
$args['post_status'] = 'publish,private,draft'; | |
return $args; | |
} | |
?> |
This file contains 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 | |
//ここからfunctions.php | |
function return_latest_id($cat_id=null) { | |
global $wpdb; | |
if(empty($cat_id)) { | |
// カスタムポストタイプ(foo、bar、hogeと仮定)を含む最新記事idの取得。 | |
$row = $wpdb->get_row("SELECT ID FROM $wpdb->posts WHERE ( post_type = 'post' OR post_type = 'foo' OR post_type = 'bar' OR post_type = 'hoge' ) AND post_status = 'publish' ORDER BY post_date DESC"); | |
} else { | |
// カテゴリを指定した最新記事idの取得 |
This file contains 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 | |
// 指定したIDの子孫を階層でリスト表示 | |
$parent = ここに親のID; | |
$args=array( | |
'child_of' => $parent | |
); | |
$pages = get_pages($args); | |
if ($pages) { | |
$pageids = array(); | |
foreach ($pages as $page) { |
This file contains 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 $title = get_the_title(); if (strlen($title) == 0)//タイトルが未入力かをチェック { ?> | |
<h2>タイトルがない場合の処理</h2> | |
<?php } else { ?> | |
<!--ある場合は普通に表示する--> | |
<h2><?php the_title(); ?></h2> | |
<?php } ?> | |
----------------------------------------------------------- |
This file contains 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 //ループ内に書く | |
$previous_post = get_previous_post(); | |
$next_post = get_next_post(); | |
$prev_value = get_post_meta( $previous_post->ID, 'CUSTOM_FIELD', $single = true); //CUSTOM_FIELDが表示したいカスタムフィールドの名前 | |
$next_value = get_post_meta( $next_post->ID, 'CUSTOM_FIELD', $single = true); | |
?> | |
<?php if ( $prev_value != '' ) : ?> |
This file contains 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
$c_message = '記事を公開します。宜しいでしょうか?'; | |
function confirm_publish(){ | |
// JavaScriptを管理画面フッターに挿入する | |
global $c_message; | |
echo '<script type="text/javascript"><!-- | |
var publish = document.getElementById("publish"); | |
if (publish !== null) publish.onclick = function(){ | |
return confirm("'.$c_message.'"); |
This file contains 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
/// WPBeginner's YouTube Share Overlay Buttons | |
function add_share_buttons($atts) { | |
// ショーートコードでYoutubeのIDを取得 | |
extract( shortcode_atts( array( | |
'video' => '' | |
), $atts ) ); | |
// 動画を表示 |
This file contains 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 ( 'wp_tag_cloud', 'tag_cloud_current_tag_highlight' ); | |
function tag_cloud_current_tag_highlight( $return ) { | |
$post_tags = array(); | |
if(is_single()) { | |
global $post; | |
$post_tags = get_the_terms($post->ID,'post_tag'); | |
} | |
if(is_tag()) { | |
$tags = explode( '+', get_query_var('tag') ); |
NewerOlder