Skip to content

Instantly share code, notes, and snippets.

View dustyf's full-sized avatar

Dustin Filippini dustyf

View GitHub Profile
@dustyf
dustyf / gist:c972e92cc20befeeaaeb
Created October 9, 2015 19:33
Get attachment ID from URL
/**
* Gets the attachment ID from a URL
* Credit: https://philipnewcomer.net/2012/11/get-the-attachment-id-from-an-image-url-in-wordpress/
**/
function pn_get_attachment_id_from_url( $attachment_url = '' ) {
global $wpdb;
$attachment_id = false;
// If there is no url, return.
@dustyf
dustyf / gist:b6e72a7a7fd05de9598e
Last active January 16, 2023 15:34
Example WordPress Simple JSON Endpoint Plugin
<?php
/**
* Plugin Name: WDS GIF API
* Plugin URI: http://webdevstudios.com
* Description: Adds a Custom Post Type to store GIFs and an API JSON Endpoint to access GIFs by a tag.
* Author: WebDevStudios
* Author URI: http://webdevstudios.com
* Version: 1.0.0
* License: GPLv2
*/
@dustyf
dustyf / gist:4bd8aaca0dd3af621fc1
Last active August 29, 2015 14:22
Add menu separator
/**
* Adds a separator in the admin menu to separate our custom menu items.
*/
function add_admin_menu_separator() {
global $menu;
$menu[29] = array(
0 => '',
1 => 'read',
2 => 'separator29',
@dustyf
dustyf / gist:9443049
Created March 9, 2014 04:50
Comic Sans Roulette
function comic_sans_roulette() {
$random = mt_rand( 0, 9 );
if ( $random == 0 ) {
echo '<style>* { font-family: "Comic Sans MS" !important; }</style>';
}
}
add_action( 'wp_head', 'comic_sans_roulette' );
@dustyf
dustyf / gist:7571030
Last active December 28, 2015 22:19
Detect IE Versions in PHP and return either the version or less than indicators.
/**
* Detect the Browser
*/
function dlf_ie() {
$ie_version = '';
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') !== false ) {
$ie_version = 'ie6';
} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7.') !== false ) {
$ie_version = 'ie7';
@dustyf
dustyf / gist:7157136
Created October 25, 2013 16:05
The following code was created for the Milwaukee WordPress Meetup on 10/24/2013 demonstrating creating custom post types, custom taxonomies, and custom fields using Advanced Custom Fields.
/**
* Below is the code generated by GenerateWP for our custom post type and our
* custom field. We pasted this into our theme's functions.php file and it
* could also be added to a plugin file.
*/
// Register Custom Post Type
function wpmke_employees() {
$labels = array(
@dustyf
dustyf / gist:5862035
Created June 25, 2013 20:26
Woo Commerce Dropdown to filter product tag within an archive page.
<?php
function displayLocationDropdown() {
$html = '';
$html .= '<form class="location-select" method="post">';
$html .= '<select id="location-selector" name="location" class="location">';
$tag = wp_tag_cloud( array(
'format' => 'array',