Skip to content

Instantly share code, notes, and snippets.

View wpexplorer's full-sized avatar
✍️
We create themes & plugins and run a popular blog about WordPress.

WPExplorer wpexplorer

✍️
We create themes & plugins and run a popular blog about WordPress.
View GitHub Profile
@wpexplorer
wpexplorer / gist:7443453
Created November 13, 2013 03:55
Adapt archive-portfolio.php with filter
<?php
/**
* @package WordPress
* @subpackage Adapt Theme
*/
?>
<?php get_header(); ?>
<?php
// Load isotope scripts
@wpexplorer
wpexplorer / gist:7652080
Created November 26, 2013 01:35
Better custom WordPress excerpts
if ( !function_exists( 'wpex_excerpt' ) ) {
function wpex_excerpt($length=30, $readmore=false ) {
global $post;
$id = $post->ID;
$meta_excerpt = get_post_meta( $id, 'wpex_excerpt_length', true );
$length = $meta_excerpt ? $meta_excerpt : $length;
if ( has_excerpt( $id ) ) {
$output = apply_filters( 'the_content', $post->post_excerpt );
} else {
$excerpt = get_the_content('');
@wpexplorer
wpexplorer / gist:7856523
Created December 8, 2013 12:04
Automatically set featured image to all posts in a post type
add_action('init','set_post_thumbnails');
function set_post_thumbnails() {
// Query args
$args = array(
'post_type' => 'testimonials',
'posts_per_page' => '-1'
);
// Run query
$query = new WP_Query( $args );
@wpexplorer
wpexplorer / gist:7856719
Created December 8, 2013 12:27
Remove WooCommerce gallery images
update_post_meta( get_the_ID(), '_product_image_gallery', '' );
@wpexplorer
wpexplorer / gist:8086713
Last active January 1, 2016 03:39
Add a shopping cart icon to WooCommerce products menu item in the WP 3.8 dashboard
// Remove WooCommerce menu.css on WP 3.8+
add_action( 'admin_print_styles', 'wpex_remove_woocommerce_admin_menu_styles' );
if ( ! function_exists('wpex_remove_woocommerce_admin_menu_styles') ) {
function wpex_remove_woocommerce_admin_menu_styles() {
global $wp_version;
if ( $wp_version >= 3.8 ) {
wp_dequeue_style( 'woocommerce_admin_menu_styles' );
}
}
}
@wpexplorer
wpexplorer / gist:8244555
Created January 3, 2014 19:19
Remove Slug From Custom Post Type URL
/**
* Remove the slug from published post permalinks. Only affect our CPT though.
*/
function wpex_remove_post_type_slug( $post_link, $post, $leavename ) {
if ( ! in_array( $post->post_type, array( 'YOUR_POST_TYPE' ) ) || 'publish' != $post->post_status )
return $post_link;
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
@wpexplorer
wpexplorer / gist:8245635
Created January 3, 2014 20:12
Next Prev - Total
if ( ! function_exists( 'wpex_next_prev' ) ) {
function wpex_next_prev() {
// Not singular so bye bye!
if ( !is_singular() ) return; ?>
<div class="clr"></div>
<ul class="post-pagination clr">
<?php previous_post_link( '<li class="post-next">%link<span>&rarr;</span></li>', true ); ?><?php next_post_link( '<li class="post-prev"><span>&larr;</span>%link</li>', true ); ?>
</ul><!-- .post-post-pagination -->
<?php }
}
@wpexplorer
wpexplorer / gist:8251585
Created January 4, 2014 04:16
Move terms from one category to another taxonomy
add_action('init', 'wpex_move_terms');
function wpex_move_terms() {
$terms = get_terms( 'category', array('child_of'=>'142'));
foreach ($terms as $term) {
wp_insert_term( $term->name, 'wpex_theme_category', array(
'slug' => $term->slug,
)
);
}
}
@wpexplorer
wpexplorer / gist:8290231
Last active January 2, 2016 10:29
Redux Typography Edit
if ( color ) {
$('#' + mainID + ' .typography-preview').css('color', color);
$('#' + mainID + ' .typography-preview').css('background-color', getContrastColour(color));
$('#' + mainID + ' .redux-typography-font-family').val(output);
$('#' + mainID + ' .typography-style .select2-chosen').text($('#' + mainID + ' .redux-typography-style option:selected').text());
$('#' + mainID + ' .typography-script .select2-chosen').text($('#' + mainID + ' .redux-typography-subsets option:selected').text());
}
@wpexplorer
wpexplorer / gist:8533997
Created January 21, 2014 03:26
Archive description
if ( is_tax() ) {
$obj = get_queried_object();
$taxonomy = $obj->taxonomy;
$term_id = $obj->term_id;
$description = term_description($term_id,$taxonomy);
if ( ! empty( $description ) ){
$output .= '<div class="clr page-subheading term-description">';
$output .= $description;
$output .= '</div>';
}