Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻

Tyler Wiegand tylerwiegand

👨‍💻
View GitHub Profile
View string_parts.php
<?php
// When you want to split strings by spaces without rounding up
function string_parts($string, $parts = 2)
{
$array = preg_split('/\s+/', $string);
if (! (count($array) > 1)) {
return $string;
}
@tylerwiegand
tylerwiegand / getPostThumbnail.php
Last active Mar 19, 2020
WP: Ultimate fallback solution to getting a thumbnail for a post
View getPostThumbnail.php
<?php
function nb_get_post_thumbnail( $post_id = null, $size = 'medium', $attr = [] ) {
if(!$post_id) {
$post_id = get_the_ID();
}
// Step 1: Use the featured image if it's there
if(!empty($image = get_the_post_thumbnail($post_id, $size, $attr))) {
return $image;