Skip to content

Instantly share code, notes, and snippets.

View AchalJ's full-sized avatar

Achal Jain AchalJ

View GitHub Profile
@AchalJ
AchalJ / code.php
Last active December 21, 2022 08:26
Posts matching filters fix for Beaver Builder Posts Grid + Content Grid
<?php // <- Ignore this
// Copy the code below and paste it to your child theme's functions.php file
add_filter( 'fl_builder_loop_query_args', function( $args ) {
$settings = $args['settings'];
$post_type = $args['post_type'];
$post__in = $post__not_in = array();
@AchalJ
AchalJ / css.css
Created November 3, 2022 17:20
Content Grid - CSS Grid to override isotope props
@media only screen and (min-width: 768px) {
.team-members-grid .pp-content-post-grid.pp-equal-height {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-auto-rows: min-content;
grid-column-gap: 3%;
grid-row-gap: 3ch;
height: auto !important;
}
.team-members-grid .pp-content-post-grid.pp-equal-height:before,
@AchalJ
AchalJ / code.php
Last active October 8, 2022 01:28
PP Taxonomy Term - Custom Shortcode to get term image URL
<?php // ignore this
// Copy the code below to your current theme's functions.php file.
// Uses: [get_term_image_url] or [get_term_image_url term_id="PROVIDE TERM ID HERE"]
add_shortcode( 'get_term_image_url', function( $atts ) {
$term_id = 0;
if ( isset( $atts['term_id'] ) && ! empty( $atts['term_id'] ) ) {
$term_id = $atts['term_id'];
} else {
@AchalJ
AchalJ / code.php
Created May 6, 2022 10:39
PowerPack Content Grid - Show only rendered products terms in filters
// PowerPack Content Grid - Show only rendered products terms in filters
add_action( 'pp_cg_before_posts', function( $settings, $query ) {
if ( 'no' == $settings->post_grid_filters_display || 'none' == $settings->post_grid_filters ) {
return;
}
add_filter( 'pp_cg_filtered_terms', function( $filtered_terms, $terms, $module_settings ) use ( $query ) {
$rendered_terms = array();
$posts = $query->get_posts();
@AchalJ
AchalJ / code.js
Created April 13, 2022 06:46
PowerPack Category Post Count animation on reveal
$(window).on('scroll.pp-animate', function() {
var scrollTop = $(window).scrollTop(),
winHeight = $(window).height(),
triggerpoint = winHeight * .8 + scrollTop;
// If module has animation, otherwise remove .fl-animated class here.
$('.animate-post-count.fl-animated .pp-category-count').each(function() {
if ( $(this).hasClass( 'revealed' ) ) {
return;
}
var counterElement = $(this).offset().top;
@AchalJ
AchalJ / code.js
Created March 28, 2022 05:40
WooPack Products Grid layout fix in PowerPack's Modal Box
(function($) {
$(document).on('pp_modal_box_rendered', function(e, $scope) {
if ( $scope.find( '.woopack-products-grid-wrap' ).length > 0 ) {
$scope.find( '.woopack-products-grid-wrap' ).each(function() {
var nodeId = $(this).closest('.fl-module').attr('data-node');
if ( 'undefined' !== typeof window['woopack_' + nodeId] ) {
var obj = window['woopack_' + nodeId];
if ( ! obj.masonry ) {
obj._gridLayoutMatchHeight();
}
@AchalJ
AchalJ / shortcode.php
Created March 25, 2022 16:43
Auto-reset Countdown Timer shortcode
/**
* How to use: [my_custom_timer id="my-timer" time="300" placeholder="00:00"]
*/
add_shortcode( 'my_custom_timer', function( $attrs ) {
// id attribute for the timer HTML.
$id = isset( $attrs['id'] ) && ! empty( $attrs['id'] ) ? $attrs['id'] : 'my-timer';
// set the time to start countdown (in seconds).
$time = isset( $attrs['time'] ) && ! empty( $attrs['time'] ) ? intval( $attrs['time'] ) : 120;
// default placeholder to appear on load
$placeholder = isset( $attrs['placeholder'] ) ? $attrs['placeholder'] : '';
@AchalJ
AchalJ / code.php
Created February 28, 2022 06:32
PowerPack Content Grid - Display taxonomy term thumbnail in post as a fallback image
add_filter( 'pp_post_image_settings_data', function( $data, $settings ) {
global $post;
if ( false !== strpos( $data['photo_src'], 'placeholder.jpg' ) ) {
$terms = get_the_terms( $post->ID, 'category' ); // Here "category" is the post taxonomy slug.
if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
$term = $terms[0];
$term_thumb_id = get_term_meta( $term->term_id, 'taxonomy_thumbnail_id', true );
@AchalJ
AchalJ / code.php
Created January 27, 2022 06:55
Shortcode to get taxonomy term description
// Using product_brand taxonomy in this example.
add_shortcode( 'product_brand_desc', function() {
if ( ! is_single() ) {
return;
}
$current_post_terms = wp_get_post_terms( get_the_ID(), 'product_brand', array( 'fields' => 'ids' ) );
$desc = '';
if ( ! is_wp_error( $current_post_terms ) && ! empty( $current_post_terms ) ) {
$current_post_term = $current_post_terms[0];
$desc = get_term_field( 'description', $current_post_term );
@AchalJ
AchalJ / shortcode.php
Created January 19, 2022 17:07
Post Featured Image Shortcode
add_shortcode( 'cg_post_featured_image', function( $attrs ) {
$args = wp_parse_args( $attrs, array(
'linked' => 'yes',
) );
$image = get_the_post_thumbnail( $post, $settings->size, array(
'itemprop' => 'image',
'class' => 'post-featured-image',
) );