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
Last active March 28, 2020 03:51
Disable Block Editor default FullScreen mode in WordPress 5.4
<?php // don't copy this line -- paste the code below into your theme's functions.php file
add_action( 'enqueue_block_editor_assets', 'jba_disable_editor_fullscreen_by_default' );
/**
* Disable Block Editor default FullScreen mode in WordPress 5.4
*
* @author @audrasjb
* @link https://jeanbaptisteaudras.com/en/2020/03/disable-block-editor-default-fullscreen-mode-in-wordpress-5-4/
*/
function jba_disable_editor_fullscreen_by_default() {
@blogjunkie
blogjunkie / style.css
Last active March 26, 2020 02:03
Fix for WPForms reCaptcha badge getting out of position
/* Fix for Convert Pro throwing reCaptcha badge out of position */
.wpforms-recaptcha-container .g-recaptcha {
transform: none !important;
}
@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
@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
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.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
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 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
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
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 );