Skip to content

Instantly share code, notes, and snippets.

View roborourke's full-sized avatar
🤠

Robert O'Rourke roborourke

🤠
View GitHub Profile
@roborourke
roborourke / wordpress-menu-and-dropdown.php
Created July 19, 2011 09:16
Code example for generating a WP menu and dropdown equivalent in sequence
<?php
$header_menu_args = array(
'theme_location' => 'header'
);
wp_nav_menu( $header_menu_args );
dropdown_menu( $header_menu_args );
@roborourke
roborourke / reload-buttons.js
Created November 1, 2011 12:41
Reloading Facebook like, Google +1 and Twitter share buttons for content loaded via AJAX
function reload_buttons() {
// facebook buttons
FB.XFBML.parse( document );
// gplus buttons
gapi.plusone.go();
// twitter buttons
twttr.widgets.load();
@roborourke
roborourke / WordPress Sticky Posts
Created December 1, 2011 16:38
Makes sticky posts in WordPress works out of the box everywhere
<?php
// stickier stickies
function fix_sticky_posts( $stickies ) {
foreach( $stickies as $sticky )
wp_update_post( array( 'ID' => $sticky, 'menu_order' => -1 ) );
return $stickies;
}
add_filter('pre_update_option_sticky_posts', 'fix_sticky_posts');
/**
* Woot!
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height:100%;
@roborourke
roborourke / blog-categories.php
Created December 19, 2011 16:44
Small plugin to allow choosing of which categories are including in the main blog list.
<?php
/*
Plugin Name: Blog Categories
Description: Adds a list of checkboxes on the reading settings page to explicitly set which categories show up in the main blog listing.
Version: 0.1
Author: Robert O'Rourke
License: GPLv2 or later
*/
@roborourke
roborourke / exclude-categories.php
Created December 19, 2011 17:06
This plugin lets you exclude categories from the standard blog posts query in WordPress
<?php
/*
Plugin Name: Exclude Categories
Description: Adds a list of checkboxes on the reading settings page to explicitly exclude categories from the main blog listing.
Version: 0.1
Author: Robert O'Rourke
License: GPLv2 or later
*/
@roborourke
roborourke / wp-stickies.php
Created January 17, 2012 11:04
Better sticky post handling for WordPress
<?php
/**
* Fixes sticky post ordering in WordPress anywhere the order is not explicitly defined.
*
* Updates a post's menu order whenever the sticky posts option is updated
*
* Props to Simon Fransson of http://dessibelle.se/ for a bugfix where 'unstickied' posts were not updated
*
* @param Array $stickies An array of post IDs
@roborourke
roborourke / wp-modify-post-type-query.php
Created January 30, 2012 15:31
Edit the main WordPress query to show items from a custom post type you specify
<?php
// replace 'post' with the id of the post type you want for your main listing
add_action( 'pre_get_posts', 'modify_main_query' );
function modify_main_query( $query ) {
if ( $query !== $wp_the_query || is_admin() )
return $query;
$query->query_vars[ 'post_type' ] = 'post';
@roborourke
roborourke / better-wp-conditional-comments.php
Created May 1, 2012 10:17
Enables !IE in wordpress's conditional comments for styles mechanism
<?php
add_filter( 'style_loader_tag', 'style_loader_tag_ccs', 10, 2 );
/**
* Add support for non IE conditional comments
*
* Trac ticket: http://core.trac.wordpress.org/ticket/16118
*
* Usage:
@roborourke
roborourke / wp-style-dropdown.php
Created May 23, 2012 13:27
Code by @alisothegeek to enable a styles dropdown in the WP tinymce editor
<?php
/*
* Custom styles for tiny mce
* HT: http://alisothegeek.com/2011/05/tinymce-styles-dropdown-wordpress-visual-editor/
*/
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );