Skip to content

Instantly share code, notes, and snippets.

@djrmom
djrmom / htaccess remote images
Created May 24, 2013 17:07
htaccess rewrite images to remove
RewriteEngine On
RewriteRule ^img.jpg http://remotesite/img.jpg
@djrmom
djrmom / theme-fonts.php
Created August 26, 2013 17:15
theme-fonts.php from hybrid-core modified so that fonts will display in mce
<?php
/**
* Theme Fonts - A script to allow users to select theme fonts.
*
* Theme Fonts was created to give theme developers an easy way to include multiple font settings
* and multiple font choices to their users. It's main purpose is to provide integration into the
* WordPress theme customizer to allow for the selection of fonts. The script will work with basic
* Web-safe fonts, custom fonts added to the theme, and fonts from Google Web Fonts.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
@djrmom
djrmom / woocommerce_filter.php
Created August 14, 2014 03:07
WooCommerce filter for variations price range. Shows text of "Starting from" with minimum price instead of price range.
add_filter( 'woocommerce_variable_price_html', 'djr_price_filter', 10, 2 );
add_filter( 'woocommerce_variable_sale_price_html', 'djr_price_filter', 10, 2 );
/**
* Filters woocommerce_variable_price_html and woocommerce_variable_sale_price_html to apply text
* of Starting from instead of the price range from - to that is the woocommerce default
*
* @param $price
* @param $product
*
* @return string
@djrmom
djrmom / multiple-front-pages.php
Created November 3, 2016 13:33
WordPress front page template hierarchy modifications
<?php
/**
* Filters frontpage_template to allow both front-page.php as default static front page template while allowing
* users to select a different template in page options, also removes front-page.php from being used for the blog index
* From discussion in https://themehybrid.slack.com/archives/general/p1474838117000393
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
function prefix_front_page_template( $template ) {
return ( is_home() || locate_template( get_page_template_slug() ) ) ? '' : $template;
@djrmom
djrmom / lister-shortcodes.php
Last active June 27, 2017 14:39
amazon lister customizations
<?php
/**
* Example code for adding custom shortcodes for WP-Lister Pro for Amazon
*/
/**
* Returns value to output in wpla shortcode
*
* @param $post_id
* @param $product
@djrmom
djrmom / remove-search.php
Created June 27, 2017 14:54
wordpress rewrites
<?php
/**
* remove search rules so that we can use /search/slug/ as a page
*
* @param $rules
*
* @return mixed
*/
function prefix_links_remove_search($rules){
<?php
/**
* Client wants only logged in users to see prices and buy non-sale items while allowing all users to see prices and buy
* on sale items
*/
/**
*
* filters woocommerce_is_purchasable for not onsale items
*
@djrmom
djrmom / custom-hooks.php
Last active August 18, 2017 12:31
facetwp hash for colors
//filter color display to maybe add hash to hex colors
add_filter( 'facetwp_facet_render_args', function( $args ) {
if ( 'colors' == $args['facet']['name'] ) {
foreach ( $args['values'] AS $key => $value ) {
$args['values'][$key]['facet_display_value'] = ( '' != ( $color = sanitize_hex_color_no_hash( $value['facet_display_value'] ) ) ) ? '#' . $color : $value['facet_display_value'];
}
}
return $args;
});
<?php
/**
* filter html for sort output to output radio buttons
*/
add_filter( 'facetwp_sort_html', function( $html, $params ) {
$html = '';
foreach ( $params['sort_options'] as $key => $atts ) {
$html .= '<input type="radio" name="custom-sort" value="' . $key . '">' . $atts['label'] . '<br>';
}
@djrmom
djrmom / custom-hooks.php
Created August 18, 2017 16:03
facetwp custom sort facet
/**
* custom sort order for a facet, this orders by facet_display_value but facet_value could also be used
**/
add_filter( 'facetwp_facet_orderby', function( $orderby, $facet ) {
if ( 'colors' == $facet['name'] ) { // change colors to the name of the facet
$orderby = "FIELD(f.facet_display_value, 'Blue','Green','Red', 'Gray')";
}
return $orderby;
}, 10, 2 );