Skip to content

Instantly share code, notes, and snippets.

View baczoni's full-sized avatar

Aron Baczoni baczoni

View GitHub Profile
@baczoni
baczoni / gist:2481130
Created April 24, 2012 16:17
Wordpress: Add searchbox to nav menu
add_filter('wp_nav_menu_items','add_search_box', 10, 2);
function add_search_box($items, $args) {
ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();
$items .= '<li>' . $searchform . '</li>';
return $items;
}
@baczoni
baczoni / gist:2481083
Created April 24, 2012 16:12
Wordpress: Disable self trackbacks
function disable_self_ping( &$links ) {
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, get_option( 'home' ) ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'disable_self_ping' );
@baczoni
baczoni / gist:2481075
Created April 24, 2012 16:11
Wordpress: Remove 'Read more' jump
function wdc_no_more_jumping($post) {
return '<a href="'.get_permalink($post->ID).'" class="read-more">'.'Continue Reading'.'</a>';
}
add_filter('excerpt_more', 'wdc_no_more_jumping');
@baczoni
baczoni / gist:2481067
Created April 24, 2012 16:09
Wordpress: Display latest Google+ post
<?php
include_once(ABSPATH.WPINC.'/rss.php');
$googleplus = fetch_feed("http://plusfeed.appspot.com/123456789..."); // Replace 123456789... by your own ID
echo '<a href="';
echo $googleplus->items[0]['link']; echo '">';
echo $googleplus->items[0]['summary'];
echo '';
?>
@baczoni
baczoni / gist:2481027
Created April 24, 2012 16:04
Wordpress: Display custom RSS feed
<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('http://wpforums.com/external.php?type=RSS2', 5); ?>
@baczoni
baczoni / gist:2481000
Created April 24, 2012 16:00
Wordpress: Use schortcodes in widgets
<?php add_filter('widget_text', 'do_shortcode') ?>
@baczoni
baczoni / gist:2480989
Created April 24, 2012 15:59
Wordpress: Additional post classes
<?php
function additional_post_classes( $classes ) {
global $wp_query;
if( $wp_query->found_posts < 1 ) {
return $classes;
}
if( $wp_query->current_post == 0 ) {
$classes[] = 'post-first';
@baczoni
baczoni / gist:2480964
Created April 24, 2012 15:55
Wordpress: Enable excerpt for pages
<?php
function my_init() {
add_post_type_support('page', array('excerpt'));
}
add_action('init', 'my_init');
?>
@baczoni
baczoni / gist:2480946
Created April 24, 2012 15:53
Wordpress: Enable featured image for posts/pages
<?php
add_theme_support( 'post-thumbnails' );
// This adds support for pages only:
add_theme_support( 'post-thumbnails', array( 'page' ) );
// And this adds support for posts only:
add_theme_support( 'post-thumbnails', array( 'post' ) );
@baczoni
baczoni / gist:2480899
Created April 24, 2012 15:48
Wordpress: Separate comments from trackbacks
<?php
// Find:
foreach ($comments as $comment) :
// Comments are displayed here
endforeach;
?>
<?php
// And replace with:
?>