Skip to content

Instantly share code, notes, and snippets.

@gyrus
gyrus / first_para_class.php
Last active December 14, 2015 03:18
Output WordPress content with a class on the first para
<?php
/**
* Output content with a class on the first para
*
* @param string $class Default: 'intro'
* @return void
*/
function pilau_the_content_first_para_class( $class = 'intro' ) {
$content = apply_filters( 'the_content', get_the_content() );
@gyrus
gyrus / carousel.js
Last active December 12, 2015 04:29
A sophisticated carousel system for use with the Pilau Starter theme (https://github.com/pilau/starter). Also dependent on the Developer's Custom Fields plugin (https://github.com/gyrus/WordPress-Developers-Custom-Fields). Successfully tested, but there may be some glitches to iron out in integrating - it was developed for one project and never …
@gyrus
gyrus / uk_postcode_regex.php
Created October 9, 2015 22:23
Regular expression to match a UK postcode
<?php
preg_match( '/([A-Za-z]{1,2}[0-9]{1,2})[\s]*([0-9][A-Za-z]{2})/', 'WC1N 3XX', $matches );
<?php
/*
Plugin Name: l3rady's CPT Structure Helper
Plugin URI: http://l3rady.com/projects/l3rady-cpt-structure-helper/
Description:
Author: Scott Cariss
Version: 0.2.1
Author URI: http://l3rady.com/
Text Domain: sccptshelper
Domain Path: /languages
@gyrus
gyrus / gist:3339396
Last active October 8, 2015 13:37
WordPress Widget Logic plugin code generator
<?php
/*
These days I prefer the Dynamic Widgets plugin (http://wordpress.org/extend/plugins/dynamic-widgets/), because
it can accommodate sophisticated widget display rules in a GUI that clients can use. However, the Widget Logic
plugin (http://wordpress.org/extend/plugins/widget-logic/) still has its place. This bit of code will add
a "Widget Logic generator" to the Widgets page, which is useful if you use this plugin and have some users
who aren't comfortable with writing the simple PHP.
@gyrus
gyrus / gist:3189303
Created July 27, 2012 17:41
Make containing elements into links
/**
* Make containing elements into links
*
* jQuery, in conjunction with two CSS classes:
*
* 'make-link' - Makes containing elements into links. Add the class '.make-link-target'
* to the descendant anchor that is linked to the URL you want the ancestor element to
* link to. The JS handles making the cursor into a pointer and adds the class 'hover'
* to the target anchor when the ancestor is hovered.
*
@gyrus
gyrus / gist:3172382
Created July 24, 2012 20:16
Remove id and class attributes from WordPress nav menus
add_filter( 'nav_menu_css_class', '__return_empty_array', 10000 );
add_filter( 'nav_menu_item_id', '__return_empty_array', 10000 );
@gyrus
gyrus / gist:3157067
Created July 21, 2012 20:32
Get menu items of WordPress nav menu attached to specified menu location
<?php
/**
* Get menu items of nav menu attached to specified menu location
*
* @uses get_nav_menu_locations()
*/
function pilau_get_menu_location_items( $location_slug, $max = 0 ) {
static $menu_locations = null;
if ( $menu_locations === null )
@gyrus
gyrus / gist:3156901
Created July 21, 2012 19:27
Put WordPress custom post types in a global variable
<?php
/**
* Store public custom post types in global variable
*/
add_action( 'init', 'pilau_custom_post_types_var', 1 );
function pilau_custom_post_types_var() {
global $pilau_custom_post_types;
$pilau_custom_post_types = get_post_types( array(
'public' => true,
@gyrus
gyrus / gist:3157207
Created July 21, 2012 21:15
Fix height of Flickr slideshows embedded in WordPress
<?php
/**
* Fix height of embedded Flickr slideshows
*/
add_filter( 'oembed_result', 'pilau_fix_flickr_slideshow_height', 10, 3 );
function pilau_fix_flickr_slideshow_height( $html, $url, $args ) {
if ( strpos( $url, "flickr.com" ) !== false && substr( $url, -6 ) == "/show/" )
$html = preg_replace( '/ height="([^"]+)"/', ' height="350"', $html );
return $html;