Skip to content

Instantly share code, notes, and snippets.

View lswilson's full-sized avatar

Lisa Sabin-Wilson lswilson

View GitHub Profile
add_action( 'template_redirect', 'ngd_multiple_logos' );
function ngd_multiple_logos() {
sp_remove_action('sb_header', 'sp_header_settings', 'logo');
sp_add_action( 'sb_header', 'ngd_logo');
}
function ngd_logo() {
// We need the $post global to determine parent_page relationships
global $post;
@lswilson
lswilson / gist:4581437
Created January 20, 2013 20:23
pre_get_posts() - Add CPT to Category and Tag pages
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','press_piece','knowledge_base_entries', 'nav_menu_item');
$query->set('post_type',$post_type);
return $query;
@lswilson
lswilson / gist:4636773
Created January 25, 2013 18:36
Returns 10 older posts
function filter_where($where = '') {
$where .= " AND post_date < '" . date('Y-m-d') . "'";
return $where;
}
// Register the filtering function
add_filter('posts_where', 'filter_where');
// Activate all sidebars, override this to customize sidebar markup
function widgets_init() {
// If there aren't any sidebars, skip the rest
if ( !$this->sidebars || empty($this->sidebars) ) return;
// Otherwise, lets register all of them
foreach ( $this->sidebars as $id => $info ) {
register_sidebar(array(
@lswilson
lswilson / gist:4661485
Created January 29, 2013 03:13
The whole darned thing.
// swap out the widget-title markup
class Drad_Sidebar_Markup extends SB_Sidebars {
// Activate all sidebars, override this to customize sidebar markup
function widgets_init() {
// If there aren't any sidebars, skip the rest
if ( !$this->sidebars || empty($this->sidebars) ) return;
// Otherwise, lets register all of them
@lswilson
lswilson / gist:4686455
Created January 31, 2013 21:08
change SB widget title markup
// swap out the widget-title markup
class Badgestack_Sidebar_Markup extends SB_Sidebars {
// Activate all sidebars, override this to customize sidebar markup
function widgets_init() {
// If there aren't any sidebars, skip the rest
if ( !$this->sidebars || empty($this->sidebars) ) return;
// Otherwise, lets register all of them
@lswilson
lswilson / gist:5199853
Last active December 15, 2015 04:09
WordPress: Image upload in a widget
<?php
/**
* NGData Widget Icons
*
* @author Lisa Sabin-Wilson
* @since 1.0
*/
class icon_text extends WP_Widget
@lswilson
lswilson / gist:5448521
Created April 24, 2013 00:05
Add Multisite Blog ID to body_class
add_action( 'body_class', 'ms_body_class' );
function ms_body_class( $class ) {
global $current_blog;
$class[] = 'ms-' . $current_blog-> blog_id;
return $class;
}
@lswilson
lswilson / gist:5665875
Last active December 17, 2015 20:09
Shorten title UTF8 (useful for cyrillic languages)
//display only first 45 characters in the title.
$short_title = mb_substr(the_title('','',FALSE),0, 45);
echo $short_title;
if (strlen( utf8_decode($short_title) ) > 44){
echo '...';
}
if ( ! function_exists( 'threatpost_get_attachment_id_from_src' ) ) {
function threatpost_get_attachment_id_from_src( $image_src ) {
global $wpdb;
$id = $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'" );
return $id;
}
}