Skip to content

Instantly share code, notes, and snippets.

@krmd
krmd / gist:00ac4b01bd8dd794288e
Created January 28, 2015 19:24
Add WooCommerce support to Themeforest Rabia
add_action( 'woocommerce_before_main_content', 'before_rabia_shop' );
function before_rabia_shop(){
echo '<section class="full-page-section global-section"><div class="row"><div class="col-md-2 navigation visible-md-block visible-lg-block">';
get_sidebar();
echo '</div><div class="col-md-10">';
}
add_action( 'woocommerce_after_main_content', 'after_rabia_shop' );
function after_rabia_shop(){
echo '</div></div></section>';
}
@krmd
krmd / gist:a0dd01ceb091d5f297b4
Created May 30, 2014 15:34
WooTheme Canvas: Add Login/Logout to Menus
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
}
return $items;
}
@krmd
krmd / gist:a66896838b23f0712cea
Created May 30, 2014 15:33
Gravity Forms: Exclude field from notification
//to exclude a field from notifications assign the field the CSS Class Name gf_exclude and then use the {all_fields:exclude} merge tag
add_filter( 'gform_merge_tag_filter', 'exclude_from_all_fields', 10, 4 );
function exclude_from_all_fields( $value, $merge_tag, $options, $field ) {
$options_array = explode( ",", $options ); //breaks options into an array
$exclude = in_array( "exclude", $options_array ); //returns TRUE if 'exclude' is found in the array
$class_array = explode( " ", $field["cssClass"] ); //breaks the fields CSS classes into an array
$exclude_class = in_array( "gf_exclude", $class_array ); //returns TRUE if 'gf_exclude' is found in the array
if ( $merge_tag == "all_fields" && $exclude == true && $exclude_class == true )
return false;
@krmd
krmd / gist:e617d21a289a8e5fcda1
Created May 30, 2014 15:32
WooCommerce: Add Category class to body tag
// add taxonomy term of products category to body classes
function woo_custom_taxonomy_in_body_class( $classes ){
if( is_singular( 'product' ) )
{
$custom_terms = get_the_terms(0, 'product_cat');
if ($custom_terms) {
foreach ($custom_terms as $custom_term) {
$classes[] = 'product_cat_' . $custom_term->slug;
}
}
@krmd
krmd / gist:92cf67de2123c7fd155a
Created May 30, 2014 15:31
Insert Span in Widget Titles
<?php
//* Do NOT include the opening php tag http://www.rickrduncan.com/wordpress/customize-wordpress-widget-titles
//* Insert SPAN tag into widgettitle
add_filter( 'dynamic_sidebar_params', 'b3m_wrap_widget_titles', 20 );
function b3m_wrap_widget_titles( array $params ) {
// $params will ordinarily be an array of 2 elements, we're only interested in the first element
$widget =& $params[0];
$widget['before_title'] = '<h4 class="widgettitle"><span class="sidebar-title">';
@krmd
krmd / gist:09ad7e7fc314bb36adc8
Created May 30, 2014 15:25
WooTheme Canvas: CSS
/* Remove Comment are Closed
.nocomments {
display: none;
}*/
/* Change User Avatoar to Square
#post-author .profile-image img, #comments .avatar img {
border-radius: 0;
-moz-border-radius: 0;
-webkit-border-radius: 0;
@krmd
krmd / gist:d4c92a31688a5de98f20
Created May 30, 2014 15:21
WooTheme: Search Result Full Content
add_action('template_redirect', 'redirect_single_post');
function redirect_single_post() {
if (is_search()) {
global $wp_query;
if ($wp_query->post_count == 1 && $wp_query->max_num_pages == 1) {
wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
exit;
}
}
}
@krmd
krmd / gist:b9305547d96faaf38c24
Last active August 29, 2015 14:02
WooTheme Canvas: Add Search Bar to Navigation
add_action( 'woo_nav_inside', 'custom_nav_searchform', 10 );
function custom_nav_searchform () {
echo '<div id="nav-search" class="nav-search fr">' . "
";
get_template_part( 'search', 'form' );
echo '</div><!--/#nav-search .nav-search fr-->' . "
";
}
//OR
@krmd
krmd / gist:dadae219f638e7d56d1f
Created May 30, 2014 15:20
WooTheme Canvas: Related Posts Thumbnails
// Start custom_add_related_posts()
add_action( 'woo_post_inside_after', 'custom_add_related_posts' );
function custom_add_related_posts () {
if ( is_single() ) {
echo '<h3>You may also like to read:</h3></br>';
echo do_shortcode('[related_posts limit="4" image="120"]');
}
} // End woo_add_related_posts()
@krmd
krmd / gist:e6fc0dccad480d50bc41
Created May 30, 2014 15:19
WooTheme Canvas: Remove Top or Primary Nav
add_action( 'init', 'remove_canvas_main_navigation', 10 );
function remove_canvas_main_navigation () {
// Remove main nav from the woo_header_after hook
remove_action( 'woo_header_after','woo_nav', 10 );
}
add_action( 'init', 'remove_canvas_top_navigation', 10 );
function remove_canvas_top_navigation () {