To change “Search this site …” add this snippet to functions.php:
Free
Change breadcrumbs home text in Genesis
Add this to functions.php
Display Google Maps location address details of ACF field without coordinates
<?php $location = get_field('location'); if( $location ) { // Loop over segments and construct HTML. $address = ''; foreach( array('street_number', 'street_name', 'city', 'state', 'post_code', 'country') as $i => $k ) { if( isset( $location[ $k ] ) ) { $address .= sprintf( '<span class="segment-%s">%s</span>, ', $k, $location[ $k ] ); } } // Trim trailing comma. $address = trim( $address, ', ' ); // Display HTML. echo '<p>' . $address . '.</p>'; }
Display title of current post’s category
$category = get_the_category(); echo $category[0]-> cat_name;
Enqueue CSS for WordPress admin
// ========================================================================= // WPADMIN CSS // ========================================================================= function admin_css() { wp_enqueue_style( 'admin_css', get_stylesheet_directory_uri() . '/assets/css/wpadmin.css' ); } add_action('admin_print_styles', 'admin_css' );
Query ACF Repeater Field with embedded Group
<!--REPEATER--> <?php if( have_rows('repeater') ): ?> <?php while( have_rows('repeater') ): the_row(); ?> <!--GROUP--> <?php if( have_rows('group') ): ?> <?php while( have_rows('group') ): the_row(); // vars $title = get_sub_field('title'); ?> <?php echo $title; ?> <?php endwhile; ?> <?php endif ?> <?php endwhile; ?> <?php endif ?>
Sticky footer in Storefront
Remove sidebar and force full width layout in Storefront
// ========================================================================= // STOREFRONT REMOVE SIDEBAR - FULL WIDTH LAYOUT // ========================================================================= function wpflames_remove_storefront_sidebar() { remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 ); add_filter( 'body_class', function( $classes ) { return array_merge( $classes, array( 'page-template-template-fullwidth page-template-template-fullwidth-php ' ) ); } ); } add_action( 'get_header', 'wpflames_remove_storefront_sidebar' );
How to use single social icon with svg sprite without include the whole Font Awesome icon set
Create a file named sprite.svg
<svg> <symbol id="fb-icon" viewbox="-20 -20 200 200"> <path fill="white" d="M91.84,71.34l3.37-21.99h-21.1V35.08c0-6.02,2.95-11.88,12.4-11.88h9.59V4.49c0,0-8.7-1.49-17.03-1.49 C61.7,3,50.35,13.53,50.35,32.59v16.76H31.04v21.99h19.31v53.15h23.77V71.34H91.84z"/></path> </symbol> </svg>
Paste this in functions.php
function add_image_sprite_map(){ include('assets/images/sprite.svg'); } add_action('storefront_before_header', 'add_image_sprite_map');
Use the icon wherever You want
<a target="_blank" href="" rel="noopener noreferrer"> <svg class="fb-svg"><use xlink:href="#fb-icon" /></svg> </a>
Enqueue script with WordPress hook
Hook Data Layer with variables for Google Tag Manager in WooCommerce
Display the selected checkbox in ACF
<?php $colors = get_field('colors'); if( $colors ): ?> <ul> <?php foreach( $colors as $color ): ?> <li><?php echo $color; ?></li> <?php endforeach; ?> </ul> <?php endif; ?>
Display title of current Custom Post Type’s taxonomy
$terms = get_the_terms( $post->ID, 'YOUR_TAXONOMY' ); foreach($terms as $term) { echo $term->name; echo $term->slug; }
jQuery Modal without Bootstrap
// ============================================================= // ENQUEUE SCRIPTS FOR MODAL // ============================================================= function storefront_enqueue_style() { wp_enqueue_style('modal_css', '//cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css', false); } add_action( 'wp_enqueue_scripts', 'storefront_enqueue_style' ); function storefront_enqueue_script() { wp_enqueue_script('modal_jquery', '//cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js', false); wp_enqueue_script('modal_js', '//cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js', false); } add_action( 'wp_enqueue_scripts', 'storefront_enqueue_script' );
HTML
<!--HTML EMBEDDED INTO THE DOCUMENT--> <div id="modal1" class="modal"> <h2>Hello World</h2> <a href="#" rel="modal:close">Close</a> </div> <!--LINK TO OPEN THE MODAL--> <p><a href="#modal1" rel="modal:open">Open Modal</a></p>
How to select “Add to cart” button with jQuery
jQuery(document).ready(function() {
jQuery(‘body’).on(‘click’, ‘.add_to_cart_button’, function() {
jQuery(this)
alert(“HELLO”);
});
});
How to Change “Place Order” text in WooCommerce Checkout
// ============================================================= // CHANGE PLACE ORDER TEXT // ============================================================= add_filter('woocommerce_order_button_html', 'change_place_order_button'); function change_place_order_button($button_html){ $button_html = str_replace('Place order', 'Order Now', $button_html); return $button_html; }
Remove sidebar from cart and checkout page in Genesis WooCommerce
// ========================================================================= //REMOVE SIDEBAR OF GENESIS CHECKOUT AND CART PAGE // ========================================================================= function remove_checkout_sidebar_genesis($opt) { if( is_checkout() || is_cart()) { $opt = 'full-width-content'; return $opt; } } add_filter('genesis_site_layout', 'remove_checkout_sidebar_genesis');
Excluded TAX for specific user role in WooCommerce
function tax_excluded_price_per_user_role( $value ) { if ( current_user_can( 'wholesale_customer' ) ) { return 'excl'; } return $value; } add_filter( 'pre_option_woocommerce_tax_display_shop', 'tax_excluded_price_per_user_role' ); add_filter( 'pre_option_woocommerce_tax_display_cart', 'tax_excluded_price_per_user_role' );
Show the price in different currency on product archive page in WooCommerce
// ========================================================================= // SHOW PRICE IN EURO // ========================================================================= function show_price_in_euro(){ global $product; if( $product->has_child() ) { $product->get_id(); $var_price_huf = $product->get_variation_price( 'min', true ); $exchange_rate = 360; $price_eur = $var_price_huf / $exchange_rate; echo '<span class="price euro"><span class="woocommerce-Price-amount amount eur">'.round($price_eur, 1).' €</span></span>'; } else{ $product->get_id(); $price_huf = $product->get_price(); $exchange_rate = 360; $price_eur = $price_huf / $exchange_rate; echo '<span class="price euro"><span class="woocommerce-Price-amount amount eur">'.round($price_eur, 1).' €</span></span>'; } } add_action('woocommerce_after_shop_loop_item', 'show_price_in_euro',-1);
Specific Shipping Method Based on Minimum Order Amount in WooCommerce
// ========================================================================= // MINIMUM ORDER AMOUNT FOR SPECIFIC SHIPPING METHOD // ========================================================================= function minimum_order_amount_for_shipping( $rates, $package ) { $threshold = 100; if ( WC()->cart->subtotal < $threshold ) { unset( $rates['flat_rate:2'] ); } return $rates; } add_filter( 'woocommerce_package_rates', 'minimum_order_amount_for_shipping', 10, 2 );