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 20, 2026 00:32
Disable page title in Hello theme if Elementor is active
<?php // Don't copy this line
function ele_disable_page_title( $return ) {
// 1. Bail early if it's a 404 page to keep the title visible
if ( is_404() || is_search() || is_archive() ) {
return $return;
}
$post_id = get_the_ID();
@blogjunkie
blogjunkie / functions.php
Last active November 9, 2025 10:21
Custom page titles for co-authors with WordPress SEO
<?php
/**
* Custom page titles for Guest Authors with WordPress SEO
* Returns "[author name]&#39;s articles on [site name]"
*
*/
add_filter('wpseo_title', 'my_co_author_wseo_title');
function my_co_author_wseo_title( $title ) {
@blogjunkie
blogjunkie / functions.php.php
Created October 17, 2025 10:35
Bulletproof check for page built with Elementor
<?php // Don't copy this line
$post_id = get_queried_object_id();
$is_elementor = false;
if ( function_exists('did_action') && did_action('elementor/loaded') ) { // Check if Elementor is loaded
$is_elementor = \Elementor\Plugin::instance()->db->is_built_with_elementor( $post_id );
} else {
// Fallback when Elementor isn't loaded: check post meta flag
$is_elementor = get_post_meta( $post_id, '_elementor_edit_mode', true ) === 'builder';
}
@blogjunkie
blogjunkie / functions.php
Created September 9, 2023 12:49
WordPress shortcode to send custom GA4 event - use it in the form confirmation message
<?php // Do not copy this line
/**
* Place this shortcode in the form confirmation message. Usage:
*
* [ga4_event] will send 'form_submit' event by default
* [ga4_event name="submit_enquiry"] to send 'submit_enquiry' event
* [ga4_event name="subscribed_to_newsletter"] to send 'subscribed_to_newsletter' event
*/
@blogjunkie
blogjunkie / functions.php
Created September 4, 2023 08:46
Exclude pages that have been noindex-ed in Rank Math from WP search
<?php // Do not copy this line
function child_exclude_noindex_from_search( $query ) {
if( $query->is_main_query() && $query->is_search() ) {
$meta_query = isset( $query->meta_query ) ? $query->meta_query : array();
$meta_query['noindex'] = array(
'key' => 'rank_math_robots',
'value' => "noindex",
@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 / functions.php.php
Created June 23, 2022 05:58
Restore Classic Widgets
<?php // Don't copy this line
function example_theme_support() {
remove_theme_support( 'widgets-block-editor' );
}
add_action( 'after_setup_theme', 'example_theme_support' );
@blogjunkie
blogjunkie / functions.php
Created January 12, 2022 08:15
Pre-fill ACF repeater sub-fields
<?php
/**
* Let's say we have an ACF repeater field with 2 sub-fields:
*
* Section
* - Title
* - Description
*
* This code snippet will automatically load 3 instances of the Section, and pre-fill the titles.
@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 11, 2021 12:12
Disable PowerPack outputting data-no-lazy in Content Grid module
<?php // don't copy this line
add_filter( 'pp_post_image_settings_data', function( $data, $settings ) {
if ( isset( $data['attributes'] ) && isset( $data['attributes']['data-no-lazy'] ) ) {
unset( $data['attributes']['data-no-lazy'] );
}
return $data;
}, 10, 3 );