Skip to content

Instantly share code, notes, and snippets.

@gyrus
gyrus / gist:3157070
Created July 21, 2012 20:34
Get WordPress nav menu without markup containers
<?php
/**
* Get nav menu without markup containers
*
* @uses wp_nav_menu()
* @param string $menu The name given to the menu in Appearance > Menus
* @param integer $depth
* @return string
*/
@gyrus
gyrus / pilau_protocol_relative_image_urls.php
Created April 16, 2015 23:59
Filter images sent to editor to make the URLs protocol-relative for possible SSL
<?php
add_filter( 'image_send_to_editor', 'pilau_protocol_relative_image_urls', 999999 );
/**
* Filter images sent to editor to make the URLs protocol-relative for possible SSL
*/
function pilau_protocol_relative_image_urls( $html ) {
// Replace protocols with relative schema
$html = str_replace( array( 'http://', 'https://' ), '//', $html );
@gyrus
gyrus / get-video-thumbnail.php
Created September 10, 2013 19:49
Get the URL of a thumbnail for a video on a 3rd-party service
<?php
/**
* Get the URL of a thumbnail for a video on a 3rd-party service
*
* @param string $url Currently supports YouTube and Vimeo
* @return string
*/
function pilau_get_video_thumbnail( $url ) {
$thumb_url = null;
@gyrus
gyrus / slideshow.js
Last active December 22, 2015 18:29
A class to manage a simple slideshow with jQuery.
/**
* Slideshow
*/
( function( $ ) {
$.PilauSlideShow = function( options ) {
/** The slideshow wrapper element */
this.el = options.el;
ul {
padding-left: 1.5em;
li {
list-style: none;
&:before {
content: '\2022';
color: @color-green;
display: block;
position: relative;
max-width: 0;
@gyrus
gyrus / sharethis-icons.php
Created July 1, 2013 11:03
Social media icons for use with ShareThis plugin, including flag to distinguish between "global" sharing of site and individual page sharing.
/**
* Output social media icons
*
* @param bool $global Global style?
* @return void
*/
function pilau_share_icons( $global = false ) {
$url = '';
if ( $global ) {
$url = ' st_url="' . home_url() . '"';
@gyrus
gyrus / breadcrumbs.php
Created June 18, 2013 22:47
WordPress breadcrumbs output
/**
* Output breadcrumbs
*
* A lot of options for formatting, but this just uses the <nav> element, plus the
* 'breadcrumb' class as per @link http://microformats.org/wiki/blog-post-formats
*
* @uses $post
* @uses is_404()
* @uses apply_filters()
* @uses pilau_breadcrumb_link()
@gyrus
gyrus / mc_signup.php
Created May 8, 2013 20:12
Minimal MailChimp custom form (for a WordPress template)
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="[grab the URL from the MC form builder]" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate">
<div id="field-firstname" class="field">
<label for="mce-FNAME" class="assistive-text"><?php _e( 'First name' ); ?></label>
<input type="text" value="" name="FNAME" class="input" id="mce-FNAME" placeholder="<?php _e( 'First name' ); ?>">
</div>
<div id="field-lastname" class="field">
<label for="mce-LNAME" class="assistive-text"><?php _e( 'Last name' ); ?></label>
<input type="text" value="" name="LNAME" class="input" id="mce-LNAME" placeholder="<?php _e( 'Last name' ); ?>">
@gyrus
gyrus / cached_data.php
Last active December 14, 2015 13:29
Generic WordPress caching with Transients API
<?php
/**
* Get data with caching
*
* Change function name, transient name, and cache timeout if necessary.
* Populate $my_data, obviously.
* "refresh" query parameter useful for manual refreshing.
*/
function pilau_get_my_data() {