Skip to content

Instantly share code, notes, and snippets.

@tiltos
tiltos / JS: Legacy Placeholders
Created February 8, 2013 04:53
Use modernizr to add placeholder text on browsers which don't support it.
if(!Modernizr.input.placeholder){
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
@tiltos
tiltos / WP: Remove item from Toolbar
Created September 10, 2012 04:36
Remove the "+ New" menu from the Toolbar
<?php
/**
* Remove the "+ New" menu from the Toolbar
*/
function remove_toolbar_new_menu() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('new-content');
$wp_admin_bar->remove_menu('comments');
}
add_action('admin_bar_menu', 'remove_toolbar_new_menu', 300);
@tiltos
tiltos / gist:2396514
Created April 16, 2012 05:39
WP: create flexslider HTML (with ACF Repeater)
<?php
$slides = get_field('slider');
foreach( $slides as $slide) {
$markup = '<img src="'. $slide['image'] .'" alt="'. $slide['alternate'] .'" >';
if( $slide['link']) {
$markup = '<a href="'. $slide['link'] .'">' . $markup . '</a>';
}
$markup = '<li>' . $markup . '</li>';
echo $markup;
};
@tiltos
tiltos / gist:2221333
Created March 27, 2012 23:11
WP: Do not allow a blank search
<?php
function make_blank_search ($query){
global $wp_query;
if (isset($_GET['s']) && ($_GET['s']=='' || $_GET['s']==' ') ){
wp_redirect( $_SERVER['SERVER_NAME'].'/map', 301 ); exit;
}
return $query;
}
add_action('pre_get_posts','make_blank_search');
?>
@tiltos
tiltos / gist:2210113
Created March 26, 2012 22:04
WP: Gravity Forms access for Editors
<?php
function add_grav_forms(){
$role = get_role('editor');
$role->add_cap('gform_full_access');
}
add_action('admin_init','add_grav_forms');
?>
@tiltos
tiltos / gist:2128243
Created March 19, 2012 23:12
WP: Remove pages from search results
<?php
function remove_pages_from_search() {
global $wp_post_types;
$wp_post_types['page']->exclude_from_search = true;
}
add_action('init', 'remove_pages_from_search');
//via http://wordpress.stackexchange.com/questions/5453/how-do-i-remove-pages-from-search
?>
@tiltos
tiltos / gist:2128212
Created March 19, 2012 23:11
WP: Limit search to post type
<?php
function mySearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','mySearchFilter');
//via http://wordpress.stackexchange.com/questions/5453/how-do-i-remove-pages-from-search
@tiltos
tiltos / gist:2042540
Created March 15, 2012 06:36
WP: Get custom taxonomy parent
<?php
$term = get_the_terms( $post->ID, 'custom-taxonomy' );
foreach ($term as $key) {
$parents = get_ancestors( $key->term_id, 'custom-taxonomy' );
foreach ($parents as $parent) {
$key = get_term($parent, 'custom-taxonomy');
$parent = $key->slug;
}
}
echo $parent;
@tiltos
tiltos / gist:2041295
Created March 15, 2012 02:21
WP: Retrieve custom taxonomy
<?php
// This returns an array of objects
$term = get_the_terms( $post->ID, 'custom_tax_name' );
// If you need all of them, then store the things you need in a array,
// otherwise you can just break the loop after one iteration
foreach ($term as $key => $obj) {
$tax_name = $obj->name;
$tax_slug = $obj->slug;