Skip to content

Instantly share code, notes, and snippets.

View wpsmithtwc's full-sized avatar

Travis Smith wpsmithtwc

View GitHub Profile
@wpsmithtwc
wpsmithtwc / filter-post-thumbnail-id.php
Created May 17, 2019 15:49 — forked from westonruter/filter-post-thumbnail-id.php
How to filter the response for get_post_thumbnail_id()
<?php
/**
* How to filter the value that would be returned by get_post_thumbnail_id()
*/
add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) {
// We want to pass the actual _thumbnail_id into the filter, so requires recursion
static $is_recursing = false;
// Only filter if we're not recursing and if it is a post thumbnail ID
{
"id": "09bdc946-77fd-43a2-b9af-36ad57e54b57",
"assetName": "/storms/hurricane/video/water-rushes-through-building-in-dominican-republic",
"schema_version": "1.1.12",
"type": "video",
"locale": "en_US",
"title": "Watch: Matthew Sends Massive Storm Surge into Building",
"teaserTitle": "Watch: Matthew Sends Massive Storm Surge into Building",
"pcollid": "storms/hurricane",
"partnercolls": [],
@wpsmithtwc
wpsmithtwc / resource-post-type.php
Created January 5, 2019 03:25
WordPress: Rewrite Tutorial
<?php
add_action( 'init', '\WPS\Plugins\Rewrite\PostTypeTaxonomy\register_cpt_resource' );
/**
* Register the custom post type
*
* @since 1.2.0
*/
function register_cpt_resource() {
$labels = array(
@wpsmithtwc
wpsmithtwc / inject-jquery.js
Created August 1, 2018 22:03
JavaScript: Inject jQuery with JavaScript into head.
;(function() {
var tag = document.createElement('script');
tag.src = '//code.jquery.com/jquery.min.js';
tag.type = 'text/javascript';
tag.async = 'true';
var hookTag = document.getElementsByTagName('head')[0];
hookTag.appendChild(tag);
})();
@wpsmithtwc
wpsmithtwc / git.sh
Created September 28, 2017 15:10
Git Functions
git commit --allow-empty -m "Trigger notification"
@wpsmithtwc
wpsmithtwc / resource-hints.js
Created September 28, 2017 14:35
JavaScript: Resource Hinting
(function() {
let isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0,
// Chrome 1+
isChrome = !!window.chrome && !!window.chrome.webstore;
console.log("isChrome: ", isChrome);
console.log("isOpera: ", isOpera);
function linkPreload(as, url) {
let l = document.createElement("link");
l.rel = "preload";
@wpsmithtwc
wpsmithtwc / install-groovy.sh
Last active September 28, 2017 13:45
Install Groovy
# While I prefer to use brew for mostly everything
# SDKMan is a better manager for all things java/groovy
# Install and manage via sdkman
curl -s "https://get.sdkman.io" | bash
# Install a latest version of groovy
sdk install groovy
# Install a specific version of groovy, e.g., 2.4.9
sdk install groovy 2.4.9
@wpsmithtwc
wpsmithtwc / create-image-id.php
Created August 30, 2017 11:56 — forked from joshuadavidnelson/create-image-id.php
Programmatically create the image attachment and return the new media upload id.
<?php
/**
* Create the image attachment and return the new media upload id.
*
* @author Joshua David Nelson, josh@joshuadnelson.com
*
* @since 03.29.2017 updated to a class, utilizing code from Takuro Hishikawa's gist linked below.
*
* @see https://gist.github.com/hissy/7352933
*
@wpsmithtwc
wpsmithtwc / my_add_menu_descriptions.php
Created July 24, 2017 17:25
Add menu with custom widget location
<?php
add_filter( 'wp_nav_menu_args', 'my_add_menu_descriptions' );
function my_add_menu_descriptions( $args ) {
if ( $args['theme_location'] != 'primary' && $args['theme_location'] != 'secondary' ) {
$args['walker'] = new Menu_With_Description;
$args['desc_depth'] = 0;
$args['thumbnail'] = true;
$args['thumbnail_link'] = false;
$args['thumbnail_size'] = 'nav_thumb';
$args['thumbnail_attr'] = array( 'class' => 'nav_thumb my_thumb', 'alt' => 'test', 'title' => 'test' );
@wpsmithtwc
wpsmithtwc / my_add_menu_descriptions.php
Last active July 24, 2017 17:24
Add description by menu location.
<?php
add_filter( 'wp_nav_menu_args', 'my_add_menu_descriptions' );
function my_add_menu_descriptions( $args ) {
if ( $args['theme_location'] == 'primary' ) {
$args['walker'] = new Menu_With_Description;
$args['desc_depth'] = 0;
$args['thumbnail'] = true;
$args['thumbnail_link'] = false;
$args['thumbnail_size'] = 'nav_thumb';
$args['thumbnail_attr'] = array( 'class' => 'nav_thumb my_thumb', 'alt' => 'test', 'title' => 'test' );