Skip to content

Instantly share code, notes, and snippets.

@shazdeh
shazdeh / gist:7663068
Last active December 29, 2015 11:19
Custom theme scripts
<?php
function custom_theme_enqueue_scripts() {
wp_dequeue_script( 'theme-script' );
wp_enqueue_script( 'theme-script', THEME_URI . '/js/themify.custom.script.js', array('jquery'), false, true );
}
add_action( 'wp_enqueue_scripts', 'custom_theme_enqueue_scripts', 12 );
@shazdeh
shazdeh / gist:7767860
Last active December 30, 2015 03:09
Attachment page redirect with a custom field. Useful when you want to link your images in a [gallery] shortcode.
<?php
function media_custom_field_support() {
add_post_type_support( 'attachment', 'custom-fields' );
}
add_action( 'init', 'media_custom_field_support' );
function do_attachment_redirect() {
if( is_attachment() && $redirect = get_post_meta( $GLOBALS['post']->ID, 'redirect', true ) ) {
wp_redirect( $redirect );
@shazdeh
shazdeh / gist:7797982
Created December 5, 2013 00:11
Flatshop: display content in the product lightbox instead of the product description text
<?php
function product_lightbox_full_text() {
if( themify_theme_is_product_lightbox() ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'the_content', 20 );
}
}
add_action( 'init', 'product_lightbox_full_text' );
@shazdeh
shazdeh / gist:7801290
Created December 5, 2013 07:03
Builder: display modules above the post content
<?php
function custom_builder_frontend_display_setup() {
global $ThemifyBuilder;
remove_filter( 'the_content', array( $ThemifyBuilder, 'builder_show_on_front' ), 11 );
add_filter( 'the_content', 'custom_builder_frontend_display', 11 );
}
add_action( 'template_redirect', 'custom_builder_frontend_display_setup' );
@shazdeh
shazdeh / gist:7812930
Created December 5, 2013 20:06
Trigger window resize event on page load
<?php
function custom_footer_scripts() { ?>
<script>
jQuery(window).load(function(){ jQuery(window).resize(); });
</script>
<?php }
add_action( 'wp_footer', 'custom_footer_scripts', 99999 );
@shazdeh
shazdeh / gist:7868242
Created December 9, 2013 06:35
WooCommerce: Show the saved percentage on the sale products in the the sale flash
<?php
function custom_product_sale_flash( $output, $post, $product ) {
$percent = ( ( $product->regular_price - $product->get_price() ) / $product->regular_price ) * 100;
return '<span class="onsale">' . __( 'Save:', 'themify' ) . round( $percent ) . '% </span>';
}
add_filter( 'woocommerce_sale_flash', 'custom_product_sale_flash', 11, 3 );
@shazdeh
shazdeh / gist:7949549
Created December 13, 2013 19:13
Respect sticky posts in category requests
<?php
function putStickyOnTop( $posts ) {
global $wp_query;
if( $wp_query->is_category() ){
$sticky_posts = get_option('sticky_posts');
$num_posts = count( $posts );
$sticky_offset = 0;
//loop over posts and relocate stickies to the front
@shazdeh
shazdeh / gist:7965581
Created December 14, 2013 22:10
Builder: less gap between the columns
.col4-1, .col4-2, .col4-3, .col3-1, .col3-2, .col2-1 {
margin-left: 1.5%;
}
.col4-1 {
width: 23.8%;
}
.col3-1 {
width: 32.3%;
}
.col4-2, .col2-1 {
@shazdeh
shazdeh / gist:8060358
Created December 20, 2013 19:51
Builder: "clean" style for Menu module
.module-menu.clean ul.nav,
.module-menu.clean ul.nav li,
.module-menu.clean li a,
.module-menu.clean li:hover,
.module-menu.clean li:active {
background: none;
border: none;
box-shadow: none;
}
@shazdeh
shazdeh / gist:8063162
Created December 20, 2013 23:16
Custom size for images displayed in attachment pages
<?php
function custom_attachment_size( $content ) {
if( is_attachment() ) {
global $post;
$content = wp_get_attachment_image( $post->ID, 'large' );
}
return $content;
}
add_filter( 'the_content', 'custom_attachment_size' );