Skip to content

Instantly share code, notes, and snippets.

@crawford252
crawford252 / functions.php
Created February 27, 2023 14:37
Owl Carousel Pro - Custom Popup Preloader
function dp_ocp_custom_loader() {
ob_start();
?>
<div class="dp-ocp-loader"><div class="my_custom_loader"></div></div>
<style>
.dp-ocp-loader {
position: absolute;
top: 50%;
left: 50%;
margin-top: -30px;
@crawford252
crawford252 / functions.php
Created October 28, 2022 16:41
The Events Calendar 6.0.2 - Breaks WP Query
function dp_test_tec( $atts ) {
$args = shortcode_atts( array(
'post_type' => array( 'tribe_events' ),
'orderby' => 'date',
'order' => 'DESC',
), $atts );
$output = '';
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
@crawford252
crawford252 / functions.php
Created October 19, 2022 16:24
Divi FilterGrid - Modify Canonical URL - Yoast
add_filter( 'wpseo_canonical', 'dfg_get_canonical_url', 10, 2 );
function dfg_get_canonical_url( $canonical_url ) {
if ( is_page( 31602 ) ) {
$page = 0;
if ( get_query_var( 'paged' ) ) {
$page = get_query_var( 'paged' );
} elseif ( get_query_var( 'page' ) ) {
$page = get_query_var( 'page' );
}
@crawford252
crawford252 / functions.php
Created October 19, 2022 14:50
Divi FilterGrid - Modify Canonical URL - All Pages Module is Added
add_filter( 'get_canonical_url', 'dfg_get_canonical_url', 10, 2 );
function dfg_get_canonical_url( $canonical_url, $post ) {
if ( has_shortcode( $post->post_content, 'dpdfg_filtergrid' ) ) {
$page = 0;
if ( get_query_var( 'paged' ) ) {
$page = get_query_var( 'paged' );
} elseif ( get_query_var( 'page' ) ) {
$page = get_query_var( 'page' );
}
@crawford252
crawford252 / functions.php
Created October 19, 2022 13:11
Divi FilterGrid - Modify Canonical URL - Single Page
add_filter( 'get_canonical_url', 'dfg_get_canonical_url', 10, 2 );
function dfg_get_canonical_url( $canonical_url, $post ) {
if ( $post->ID === 12 ) {
$page = 0;
if ( get_query_var( 'paged' ) ) {
$page = get_query_var( 'paged' );
} elseif ( get_query_var( 'page' ) ) {
$page = get_query_var( 'page' );
}
@crawford252
crawford252 / functions.php
Created October 17, 2022 18:57
Divi FilterGrid - Child Terms of Current Term - Custom Filters
function dpdfg_custom_filters( $filters, $props ) {
if ( $props['conditional_tags']['is_archive'] === 'on' && $props['custom_query'] === 'archive' ) {
$term_id = $props['the_ID'];
$term = get_term( $term_id );
$tax = $term->taxonomy;
$child_terms_hierarchy = Dp_Dfg_Utils::get_taxonomy_hierarchy( $tax, $term_id );
$custom_filters = dpdfg_build_custom_filters_hierarchy( $tax, array(
'0%%' . $tax => array(
array(
'id' => 'all',
@crawford252
crawford252 / functions.php
Created October 10, 2022 20:21
Divi FilterGrid - Add Product Visibility Taxonomy
add_filter( 'dpdfg_allowed_taxonomies', 'dpdfg_allowed_taxonomies' );
function dpdfg_allowed_taxonomies( $taxonomies ) {
$product_visibility = get_taxonomy( 'product_visibility' );
if ( $product_visibility ) {
$taxonomies[ $product_visibility->name ] = $product_visibility->label;
}
return $taxonomies;
}
@crawford252
crawford252 / custom.js
Created May 26, 2022 21:01
Divi FilterGrid - Previous Page Active Filter
<script>
jQuery(document).ready(function($){
$('.dp-dfg-filter a').each(function() {
var filterCat = $(this).attr('data-term-id');
var URL = '?dfg_active_filter='+filterCat;
$(this).prop('href', URL);
$(this).on('click', function() {
window.history.replaceState(null, null, URL);
})
@crawford252
crawford252 / functions.php
Created February 14, 2022 18:38
Divi Dynamic Gallery - Custom Image IDs Filter
add_filter( 'dpddg_custom_images_ids', 'dpddg_custom_images_ids', 10, 2 );
function dpddg_custom_images_ids( $gallery_ids, $props ) {
if ( $props['module_id'] === 'photo-gallery' ) {
$gallery_ids = explode( ',', get_post_meta( $props['the_ID'], $props['dynamic_content_field'], true ) );
}
return $gallery_ids;
}
@crawford252
crawford252 / functions.php
Created February 7, 2022 21:03
Divi FilterGrid - Video Preview - Media Library
add_filter( 'dpdfg_first_video_data', 'dpdfg_first_video_data', 10, 3 );
function dpdfg_first_video_data( $video_data, $post_id, $props ) {
if ( function_exists( 'get_field' ) ) {
$video_url = get_field( 'my_acf_file_field', $post_id );
if ( $video_url ) {
$video_data['video_url'] = $video_url;
$video_data['video_output'] = do_shortcode( '[video src="' . $video_url . '"]' );
}
}