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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
/** | |
* Wrap embed html with bootstrap responsive embed div | |
*/ | |
function bootstrap_embed( $html, $url, $attr ) { | |
if ( ! is_admin() ) { | |
return "<div class=\"embed-responsive embed-responsive-16by9\">" . $html . "</div>"; | |
} else { | |
return $html; | |
} | |
} |
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
function get_vimeoid( $url ) { | |
$regex = '~ | |
# Match Vimeo link and embed code | |
(?:<iframe [^>]*src=")? # If iframe match up to first quote of src | |
(?: # Group vimeo url | |
https?:\/\/ # Either http or https | |
(?:[\w]+\.)* # Optional subdomains | |
vimeo\.com # Match vimeo.com | |
(?:[\/\w]*\/videos?)? # Optional video sub directory this handles groups links also | |
\/ # Slash before 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
function get_image_attachments( $size = 'thumbail', $ID ) { | |
$featured_image_id = get_post_thumbnail_id( $ID ); | |
$args = array( | |
'post_type' => 'attachment', | |
'post_mime_type' => 'image', | |
'numberposts' => -1, | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'post_parent' => $ID, | |
'exclude' => $featured_image_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
String.prototype.repeat = function (num) { | |
return new Array(num + 1).join(this); | |
}; |
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 | |
function get_ytid( $url ) { | |
preg_match( "#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $matches ); | |
return $matches[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 | |
// In functions.php | |
add_action( 'template_redirect', 'redirect_template' ); | |
function redirect_template() { | |
global $post; | |
if ( is_single() && is_post_type( 'custompost' ) ) { | |
wp_redirect( home_url() . '/custompost/' ); |
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 | |
global $post; | |
$args = array( | |
'post_type' => 'post', | |
'posts_per_page' => -1 | |
); | |
$new_query = new WP_Query($args); | |
$post_count = 0; | |
$total_posts = $new_query->post_count; | |
?> |
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 | |
// Twitter date format example: "created_at": "Mon Jun 27 19:32:19 +0000 2011" | |
function from_apachedate( $date ) { | |
list( $D, $M, $d, $h, $m, $s, $y ) = sscanf( $date, "%s %s %2d %2d:%2d:%2d +0000 %4d" ); | |
return strtotime( "$d $M $y $h:$m:$s" ); | |
} | |
// human_time_diff is a WordPress function | |
echo human_time_diff( from_apachedate( $item->created_at ), current_time( 'timestamp' ) ); |