Skip to content

Instantly share code, notes, and snippets.

@hereswhatidid
hereswhatidid / style-conditional.php
Created July 11, 2013 21:49
Add an IE conditional requirement to an registered style in WordPress
<?php
if ( !is_admin() ) {
$theme = get_theme( get_current_theme() );
wp_register_style( 'your-style', get_bloginfo( 'stylesheet_directory' ) . '/css/ie.css', false, $theme['Version'] );
$GLOBALS['wp_styles']->add_data( 'your-style', 'conditional', 'lte IE 8' );
wp_enqueue_style( 'your-style' );
}
?>
@hereswhatidid
hereswhatidid / get-field-extended.php
Last active December 19, 2015 21:58
Extends the default Advanced Custom Fields get_field function to allow options for a default value and fallback to global options value.
<?php
if ( ! function_exists( 'get_field_ext' ) && ( function_exists( 'get_field' ) ) ) {
/**
* Extends the default ACF get_field function to allow options for a default value and fallback to global option
*
* @author Gabe Shackle <gabe@hereswhatidid.com>
* @param string $name Field name
* @param mixed $default Default value if none found
* @param integer $id Post ID to check the field value of
* @return mixed Value after running checks
@hereswhatidid
hereswhatidid / extend-sample.less
Last active December 20, 2015 05:49
Sample of nested LESS extend use
// Here is what I have in the LESS
.furniture-details {
text-align: justify;
*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.detail-column {
display: inline-block;
vertical-align: top;
text-align: left;
@hereswhatidid
hereswhatidid / video-override.php
Created August 8, 2013 03:33
Override the default video dimensions via filter
<?php
function override_video_dimensions( $out, $pairs, $atts ) {
$out['width'] = '768';
$out['height'] = '583';
return $out;
}
add_filter( 'shortcode_atts_video', 'override_video_dimensions', 10, 3 );
?>
@hereswhatidid
hereswhatidid / sample-shortcode.php
Created August 8, 2013 20:27
Enable shortcode attribute override filter to a sample shortcode
<?php
add_shortcode('sample', 'sample_shortcode');
function sample_shortcode($attr, $content = null) {
extract(shortcode_atts(array(
'title' => 'Hello, World!',
'testatt' => 'itworks'
), $attr, 'sample'));
@hereswhatidid
hereswhatidid / custom-post-type.php
Created August 15, 2013 20:22
Register Post Type with all parameters visible
<?php
// Register Custom Post Type
function custom_post_type() {
$labels = array(
'name' => _x( 'Products', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Product', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Product', 'text_domain' ),
'parent_item_colon' => __( 'Parent Product:', 'text_domain' ),
'all_items' => __( 'All Products', 'text_domain' ),
@hereswhatidid
hereswhatidid / add-figure-attribute.php
Created August 16, 2013 15:27
Add a custom attribute to the 'caption' shortcode
<?php
/**
* Add custom attribute to the 'caption' shortcode
*
* ex:
* [caption id="attachment_883" align="alignnone" width="259" use_figure="yes"]<a href="image.jpg"><img class="size-full wp-image-883" alt="This is a caption." src="image.jpg" width="259" height="195" /></a> This is a caption.[/caption]
*
* @param array $out The output array of shortcode attributes
* @param array $pairs The array of accepted parameters and their defaults
* @param array $atts The input array of shortcode attributes
@hereswhatidid
hereswhatidid / display-themes-plugins.php
Last active December 21, 2015 09:29
Display currently active post types and list their source.
<?php
add_action( 'registered_post_type', 'display_registered_post_types', 99999, 2 );
global $tempPostTypes;
$tempPostTypes = array();
function display_registered_post_types( $post_type, $args ) {
global $tempPostTypes;
@hereswhatidid
hereswhatidid / composer.json
Last active December 22, 2015 20:49
Install a WordPress stack via Composer that includes a few plugins and the Roots.io theme.
{
"name" : "hereswhatidid/install-wordpress-test",
"description" : "Test project for WordPress stack via Composer",
"authors" : [
{
"name" : "Gabe Shackle",
"email" : "gabe@hereswhatidid.com",
"homepage": "http://www.hereswhatidid.com/"
}
],
@hereswhatidid
hereswhatidid / functions.php
Created September 19, 2013 15:49
Add custom javascript to page head in WordPress
<?php
add_action( 'wp_head', 'header_scripts' );
function header_scripts() {
echo '<!--Start of Zopim Live Chat Script-->'."\n";
echo '<script type="text/javascript">'."\n";
echo 'window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s='."\n";
echo 'd.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.'."\n";
echo '_.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute(\'charset\',\'utf-8\');'."\n";
echo '$.src=\'//v2.zopim.com/?1JmbWASHEGvl7oxKGkdaQzNfQYWLE7El\';z.t=+new Date;$.'."\n";