Skip to content

Instantly share code, notes, and snippets.

@crawford252
crawford252 / functions.php
Created April 5, 2024 16:55
Divi Dynamic Gallery - Custom Overlay Click Action
function dpddg_image_overlay_action( $default_action, $props, $post_id ) {
$click_action = get_post_meta($post_id, 'ddg_click_action', true);
if(!empty($click_action)) {
switch($click_action) {
case 'none':
return 'none';
case 'custom_link':
return 'link';
case 'lightbox':
return 'lightbox';
@crawford252
crawford252 / style.css
Last active March 21, 2024 19:21
Divi Theme CSS Icon
.add_divi_icon li:before {
content: "\e052";
font-family: ETmodules;
font-size: 1em;
color: green;
position: relative;
margin-right: 5px;
}
.add_divi_icon li {
@crawford252
crawford252 / index.html
Last active March 21, 2024 18:49
Divi Theme HTML Icon
<span class='et-pb-icon' style="font-size: 32px; color: red;">&#xe052;</span>
@crawford252
crawford252 / functions.php
Created March 4, 2024 18:21
Divi Change Projects Slug
<?php
function my_custom_projects_slug( $slug ) {
$slug = array( 'slug' => 'custom-slug' );
return $slug;
}
add_filter( 'et_project_posttype_rewrite_args', 'my_custom_projects_slug', 10, 2 );
@crawford252
crawford252 / functions.php
Last active February 21, 2024 20:51
Divi FilterGrid - Custom Sort Dropdown
add_filter( 'dpdfg_custom_sorting_html', 'dpdfg_custom_sorting_html', 10, 2 );
function dpdfg_custom_sorting_html( $sorting_options_html, $props ) {
if ( $props['module_id'] === 'custom-sorting' ) {
$sorting_options_html = sprintf( '
<div class="dp-dfg-sort-orderby">
<div class="dp-dfg-filters-dropdown closed" data-parent="0">
<p class="dp-dfg-dropdown-label"><span class="dp-dfg-dropdown-placeholder" data-text="%1$s&nbsp;">%1$s</span></p>
<ul>
<li class="dp-dfg-sort-option" data-value="date" data-order-value="ASC">%2$s</li>
@crawford252
crawford252 / functions.php
Last active January 18, 2024 16:19
Divi FilterGrid - Alter Query
add_filter( 'dpdfg_ext_set_query_arguments', 'dpdfg_ext_set_query_arguments', 10, 2 );
function dpdfg_ext_set_query_arguments( $query_args, $props ) {
if ( isset( $props['module_class'] ) && $props['module_class'] === 'related-recipes' ) {
$query_args['post_type'] = 'recipe';
}
return $query_args;
}
function dp_assign_post_year_term($post_id, $post, $update) {
// Assign for new posts only
if($update) {
return;
}
// Assign only if post type is "post"
if ( 'post' !== $post->post_type ) {
return;
}
@crawford252
crawford252 / functions.php
Created August 16, 2023 12:23
Loop through existing posts and add year and month terms based on publish date
/* ONLY RUN THIS FUNCTION ONE TIME */
function dp_set_publish_date_taxonomy_all_posts() {
$posts = get_posts(array(
'post_type' => 'post',
'posts_per_page' => -1,
));
foreach ($posts as $post) {
$post_id = $post->ID;
@crawford252
crawford252 / functions.php
Last active July 27, 2023 19:35
Divi FilterGrid - Custom Content - Custom Icons Based on Terms
function dpdfg_after_read_more($content, $props) {
// get duration custom field
$duration = get_post_meta( get_the_ID(), 'duree', true );
$taxonomy1_icon = '';
$taxonomy2_icon = '';
$difficulte_terms = get_the_terms(get_the_ID(), 'difficulte');
if ( $difficulte_terms && ! is_wp_error( $difficulte_terms ) ) {
foreach( $difficulte_terms as $term ) {
@crawford252
crawford252 / custom.js
Last active May 9, 2023 15:58
Divi FilterGrid - Trigger Filter Click on Meta Terms
<script>
jQuery(document).ready(function ($) {
/* LOAD THE FUNCTION BELOW ON PAGE LOAD */
dfg_trigger_filter_by_term_link();
/* LOAD IT AGAIN AFTER DFG COMPLETES AN AJAX CALL AND THE DOM IS UPDATED */
$(document).on('dfg_after_ajax', function () {
dfg_trigger_filter_by_term_link();
});