Skip to content

Instantly share code, notes, and snippets.

View blogjunkie's full-sized avatar

David Wang blogjunkie

View GitHub Profile
@blogjunkie
blogjunkie / functions.php.php
Created February 19, 2021 03:30
Add custom fonts to Elementor from your theme
<?php // Don't include this line
/**
* Add new font group (Custom) to the top of the list
*/
add_filter( 'elementor/fonts/groups', function( $font_groups ) {
$new_font_group = array( 'custom' => __( 'Custom' ) );
return array_merge( $new_font_group, $font_groups );
} );
@blogjunkie
blogjunkie / woocommerce_variation_is_active.php
Created February 1, 2021 05:55 — forked from plugin-republic/woocommerce_variation_is_active.php
Grey out variations that are out of stock for WooCommerce
/**
* Disable out of stock variations
* https://github.com/woocommerce/woocommerce/blob/826af31e1e3b6e8e5fc3c1004cc517c5c5ec25b1/includes/class-wc-product-variation.php
* @return Boolean
*/
function wcbv_variation_is_active( $active, $variation ) {
if( ! $variation->is_in_stock() ) {
return false;
}
return $active;
@blogjunkie
blogjunkie / functions.php.php
Created November 8, 2020 09:15
Register a new image size, then make it selectable in Image Size options
<?php // Do not copy this line
/**
* Register a "Wide" image size and add it to the Image Size options
* after "Large" i.e. Thumnail, Medium, Large, Wide, Full Size
* to correspond with Align Wide and Align Full alignments
*/
// Add a new "Wide" image size
add_image_size( 'wide', 1200, 0 );
@blogjunkie
blogjunkie / functions.php
Last active November 24, 2021 09:52
Add 'Awaiting pre-order' custom status to WooCommerce with bulk edit and custom status color
<?php // Don't copy this line
/**
* Add 'Awaiting pre-order' custom status
*
* 1. Register new order status
* 2. Add to list of WC order statuses
* 3. Add your custom bulk action in dropdown
* 4. Bulk action handler
* 5. Admin notices for bulk action
@blogjunkie
blogjunkie / functions.php.php
Last active September 14, 2020 10:13
Astra enhancements for block editor
<?php // don't include this tag
add_filter( 'astra_block_editor_dynamic_css', 'child_block_editor_inline_styles' );
function child_block_editor_inline_styles( $styles ) {
$styles .= '
.editor-styles-wrapper .wp-block{
max-width: ' . astra_get_option('blog-single-max-width') . 'px;
@blogjunkie
blogjunkie / functions.php.php
Created September 14, 2020 09:20
Quickly add CSS for block editor
<?php // Don't include this opening tag
/**
* Add inline styles to admin head
*/
add_action( 'admin_head', 'child_block_editor_styles' );
function child_block_editor_styles() {
if ( 'post' == get_post_type() ) :
?>
@blogjunkie
blogjunkie / functions.php.php
Last active September 2, 2020 02:52
Remove sources (thumbnails) from the srcset array
<?php
add_filter( 'wp_calculate_image_srcset', 'child_hero_image_srcset', 10, 5 );
/**
* Remove sources from the srcset array
* Only use large and above
*
* @link https://www.smashingmagazine.com/2016/09/responsive-images-in-wordpress-with-art-direction/
*/
function child_hero_image_srcset( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
@blogjunkie
blogjunkie / functions.php.php
Last active September 2, 2020 02:53
WP-Rocket customizations - Code Snippet
<?php
/**
* Disable page caching in WP Rocket.
*
* @link http://docs.wp-rocket.me/article/61-disable-page-caching
*/
add_filter( 'do_rocket_generate_caching_files', '__return_false' );
@blogjunkie
blogjunkie / functions.php
Created June 11, 2020 11:52
Exclude pages that have been noindex-ed in Yoast SEO from WP search
<?php // Do not copy this line
add_filter( 'pre_get_posts', 'dw_exclude_noindex_content_from_search' );
function dw_exclude_noindex_content_from_search($query) {
// Only run this query for searches when not inside the admin
if ( $query->is_search && !is_admin() ) {
// Find all posts with `_yoast_wpseo_meta-robots-noindex` postmeta that equal to `1`
@blogjunkie
blogjunkie / functions.php.php
Created May 8, 2020 14:17
Replace Buy Now with Learn More on some product categories
<?php
add_action( 'woocommerce_before_shop_loop', 'onn_modify_affiliates_category_buttons' );
function onn_modify_affiliates_category_buttons() {
if ( is_product_category() ){
global $wp_query;
// Get current product category