Skip to content

Instantly share code, notes, and snippets.

View roborourke's full-sized avatar
🤠

Robert O'Rourke roborourke

🤠
View GitHub Profile
@roborourke
roborourke / embed-gist.php
Created June 13, 2012 22:17
Adds autoembedding of gist urls in WordPress
<?php
/**
* Usage:
* Paste a gist link into a blog post or page and it will be embedded eg:
* https://gist.github.com/2926827
*
* If a gist has multiple files you can select one using a url in the following format:
* https://gist.github.com/2926827?file=embed-gist.php
*/
@roborourke
roborourke / wp-set-excerpt-length.php
Created July 26, 2012 11:56
Set excerpt length on the fly in wordpress.
<?php
/**
* Sets the excerpt length for the output of the next excerpt
*
* @param int $length the number of words to show
*
* @return void
*/
function set_excerpt_length( $length = 50 ) {
@roborourke
roborourke / non-default-feed.php
Created September 24, 2012 11:56
Replace default feed in WordPress
<?php
add_action( 'init', 'use_alt_feed' );
function use_alt_feed() {
if ( is_feed() && is_post_type_archive( 'my_post_type' ) ) {
$feed = get_default_feed();
remove_action( 'do_feed_' . $feed, 'do_feed_' . $feed );
@roborourke
roborourke / lesscss-error-workarund.php
Created September 25, 2012 19:07
lesscss-parser erro workaround
<?php
$lessc = new lessc();
$lessc->registerFunction('foo', function($arg) {
list($type, $delimiter, $values) = $arg;
// $values is not flat array when using variables within arguments
// We cannot easily read the compiled value
$string = 'mod-';
if ( is_array( $values ) ) {
foreach( $values as $value ) {
@roborourke
roborourke / script.js
Created November 22, 2012 11:49
Hide get_header() and get_footer() calls when loading wp URLs not via wp ajax
// makes sure every ajax request has the 'is_ajax' parameter sent whether its using the WP ajax API or not
$.ajaxSetup( {
data: { is_ajax: 1 }
} );
@roborourke
roborourke / external-icon.css
Created December 5, 2012 12:15
Adding an external link icon to entry titles
/* show a little arrow image */
.icon-external {
display: inline!important;
float: none!important; margin: 0 0 0 4px!important;
vertical-align: baseline!important;
}
@roborourke
roborourke / wp-always-show-date.php
Created December 10, 2012 14:52
Turn off the date display hiding logic in WP if posts are on same day
<?php
/**
* Switch off is_new_day() date hiding logic
*/
add_action( 'the_post', function( $post ) {
global $previousday;
$previousday = 0;
} );
@roborourke
roborourke / basic-html5-menu-wp.php
Last active December 10, 2015 00:58
Super basic html5 menu output for WordPress
<?php
class Simple_Menu extends Walker_Nav_Menu {
// prevent sub menu wrapping
function start_lvl( &$output, $depth ) {
$output .= "\n";
}
function end_lvl( &$output, $depth ) {
@roborourke
roborourke / add_feed.php
Last active April 11, 2022 22:47
add_feed() example for WordPress
<?php
class custom_feed {
public $feed = 'custom-xml';
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
@roborourke
roborourke / wp-editor-styles.php
Created June 4, 2013 17:01
Styles dropdown in WP
<?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' );