Skip to content

Instantly share code, notes, and snippets.

Avatar

Joshua Nelson joshuadavidnelson

View GitHub Profile
@joshuadavidnelson
joshuadavidnelson / example-output.html
Last active Jul 24, 2020
Using WordPress responsive images for css background-image property, in-line styling
View example-output.html
<style>
.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-300x151.png)
}
@media only screen and (min-width: 300px) {.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-768x386.png)
}}
@media only screen and (min-width: 768px) {.header {
background-image: url(http://local.dev/wp-content/uploads/2016/04/image-1024x515.png)
}}
@joshuadavidnelson
joshuadavidnelson / wpexternalapi.php
Created Mar 12, 2016 — forked from chrisgoddard/wpexternalapi.php
WordPress External API endpoint class
View wpexternalapi.php
/*
WpExternalApi class use
$api = WpExternalApi::get('url-slug');
will create endpoint at www.example.com/url-slug/json and www.example.com/url-slug/xml
$api->set_logic(callback);
function callback($input){
@joshuadavidnelson
joshuadavidnelson / gravity-form-cmb2-options.php
Last active Aug 5, 2018
A function to return an array of gravity forms for a CMB2 select field.
View gravity-form-cmb2-options.php
<?php
/**
* Get an array of gravity forms.
*
* @since 1.0.0
*
* @return void
*/
function jdn_gf_options() {
$form_array = array();
@joshuadavidnelson
joshuadavidnelson / remove-home-from-genesis-breadcrumps.php
Created Feb 21, 2016
Filter out the "home" from genesis breadcrumbs.
View remove-home-from-genesis-breadcrumps.php
<?php
/**
* Remove the "home" value from the genesis breadcrumbs.
*
* @since 1.0.0
*
* @param array $crumbs
* @param array $args
* @return array
@joshuadavidnelson
joshuadavidnelson / basic-dropdown-usage.php
Last active Sep 2, 2020
Filter wp_dropdown_categories by post type.
View basic-dropdown-usage.php
<?php
/**
* Using wp_dropdown_categories with the post type filter applied.
*
* @link https://joshuadnelson.com/category-taxonomy-dropdown-filtered-by-post-type/
*/
// Taxonomy dropdown arguments
$args = array(
'taxonomy' => 'department',
@joshuadavidnelson
joshuadavidnelson / menu-breadcrumbs.php
Last active Feb 29, 2016
Possible route to passing duplicate menu items in Menu Breadcrumbs through a filter for use in the theme. Per https://github.com/jchristopher/menu-breadcrumb/issues/7
View menu-breadcrumbs.php
<?php
/**
* Retrieve the current Menu item object for the current Menu.
*
* @since 1.0.0
* @return bool|WP_Post The current Menu item
*/
public function get_current_menu_item_object() {
$current_menu_item = false;
@joshuadavidnelson
joshuadavidnelson / get-event-add-to-calendar.php
Last active Feb 5, 2016
Helper functions for compiling date and ical outputs with event calendar
View get-event-add-to-calendar.php
<?php
/**
* Get the "Add to Calendar" button output, used with addevent.com service.
*
* @see https://www.addevent.com/buttons/add-to-calendar
*
* @uses event_is_multiday()
* @uses wp_trim_characters()
*
* @param int $post_id
@joshuadavidnelson
joshuadavidnelson / wp-darksky-weather-icon-example.php
Last active Aug 17, 2017
Extending the WP-DarkSky helper class and adding some Weather Icons by Eric Flowers.
View wp-darksky-weather-icon-example.php
<?php
/**
* A helper class for that extends the WP-DarkSky helper class with Weather Icons.
*
* You'll need to add the Weather Icons stylesheet, web fonts, etc and enqueue them correctly.
*
* @see weathericons.io
* @see https://developer.wordpress.org/reference/functions/wp_enqueue_style/
* @see https://darksky.net/dev/docs/
*
View wp-darksky-basic-example.php
<?php
/**
* Basic example of WP-DarkSky useage.
*
* @since 01-04-2017 - Updated for new Dark Sky API & Naming
*
* @link https://github.com/joshuadavidnelson/wp-darksky
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
@joshuadavidnelson
joshuadavidnelson / forecast-io.php
Created Feb 1, 2016
Typical Forecast.io JSON Response (show here for
View forecast-io.php
Array (
[latitude] => 48.7502
[longitude] => 122.475
[timezone] => Asia/Shanghai
[offset] => 8
[currently] => Array
(
[time] => 1454306959
[summary] => Clear
[icon] => clear-day
You can’t perform that action at this time.