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 <[email protected]>
* @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 / web.config
Last active March 10, 2020 15:39
Web.config for enabling Roots WordPress theme URL rewrites
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Roots Rewrite CSS" stopProcessing="true">
<match url="^assets/css/(.*)" ignoreCase="false" />
<action type="Rewrite" url="/wp-content/themes/roots/assets/css/{R:1}" appendQueryString="true" />
</rule>
<rule name="Roots Rewrite JS" stopProcessing="true">
@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 / shortcode-detect.php
Created August 14, 2013 19:56
Detect shortcode use and enqueue scripts accordingly
<?php
function detect_video_shortcode() {
global $post;
if ( has_shortcode( $post->post_content, 'video') ) {
wp_enqueue_script( 'video-player-specific-script');
}
}
add_action( 'wp_head', 'detect_video_shortcode');
?>
@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;