Skip to content

Instantly share code, notes, and snippets.

View sagarjadhav's full-sized avatar

Sagar Jadhav sagarjadhav

  • rtCamp Inc
  • Pune
View GitHub Profile
@sagarjadhav
sagarjadhav / wp-image-alt-attr.php
Created October 12, 2021 12:07
Filter attachment image attributes to inject alt attribute to Image
<?php
if ( ! function_exists( 'rtcamp_add_img_alt_attribute' ) ) {
/**
* Filter attachment image attributes to inject alt attribute.
*
* @param string[] $attrs Array of attribute values for the image markup, keyed by attribute name.
* @param WP_Post|null $attachment Image attachment post.
* @return string[] Filtered attributes.
*/
@sagarjadhav
sagarjadhav / slick-customPaging-img.js
Created October 4, 2021 15:57
Slick slider custom Paging with Image and accessibility
$( document ).on( 'ready', () => {
$( '.slider-nav' ).slick( {
responsive: [
{
breakpoint: 767,
settings: {
dots: true,
customPaging: function( slick, index ) {
var targetImage = slick.$slides.eq( index ).find( 'img' ).attr( 'src' );
return '<button><img src=" ' + targetImage + ' " alt="image" /></button>';
$( '<ul id="bp-members-order-by" class="bs-dropdown bs-dropdown-order" />' ).appendTo( '#bp-members-order-select' );
$( '#members-order-by option' ).each(function() {
var el = $(this);
$('<li />', {}).appendTo( '#bp-members-order-by' );
$('<a />', {
'href' : el.attr( 'value' ),
'text' : el.text()
@sagarjadhav
sagarjadhav / gf_tabindex.php
Created September 15, 2017 03:54
Fix Gravity Form Tabindex Conflicts
<?php
/**
* Fix Gravity Form Tabindex Conflicts
*/
if ( !function_exists( 'gform_tabindexer' ) ) {
function gform_tabindexer( $tab_index, $form = false ) {
$starting_index = 1000;
if ( $form ) {
@sagarjadhav
sagarjadhav / ipad-hover-dropdown.js
Created August 23, 2017 15:52
Drop-Down Navigation: Touch-Friendly
;(function( $, window, document, undefined )
{
$.fn.doubleTapToGo = function( params )
{
if( !( 'ontouchstart' in window ) &&
!navigator.msMaxTouchPoints &&
!navigator.userAgent.toLowerCase().match( /windows phone os 7/i ) ) return false;
this.each( function()
{
@sagarjadhav
sagarjadhav / image-cropping.php
Last active April 21, 2017 12:15
Image cropping fix
<?php
if ( has_post_thumbnail( $post_id ) ) {
// Get Featured Image
$class = 'img-thumb';
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
$image_exists = wp_get_attachment_image_src( $post_thumbnail_id, 'thumbnail-size' );
if ( !$image_exists[ 3 ] ) {
$class = 'img-not-thumb';
}
@sagarjadhav
sagarjadhav / css-aspect-ratio-to-have-images-of-same-height.css
Created March 18, 2017 16:38
Css aspect ratio to have images of same height
.img-parent img {
position: relative;
overflow: hidden;
padding-bottom: 69.44%; /* Calculated = height / width * 100 */
display: block;
}
.img-parent img {
position: absolute;
top: 0;
@sagarjadhav
sagarjadhav / excerpt-limit.php
Created March 8, 2017 07:40
Limit the wp excerpt
<?php
/* !
* Function to trim excerpt
*/
if ( !function_exists( 'limit_excerpt' ) ) {
function limit_excerpt( $lenght, $text ) {
$content = substr( $text, 0, $lenght );
if ( strlen( $content ) < strlen( $text ) ) {
@sagarjadhav
sagarjadhav / wp-admin-body-class.php
Created December 3, 2016 10:19
Add class to body in admin section
<?php
// Add class to body in admin section
function admin_body_classes($classes) {
$classes .= 'no-adminbar';
return $classes;
}
add_filter( 'admin_body_class', 'admin_body_classes' );
@sagarjadhav
sagarjadhav / flex-clearfix.css
Created December 1, 2016 06:53
Flexbox, clear fix and pseudo elements in Safari and Chrome
.clearfix:before,
.clearfix:after {
flex-basis: 0;
order: 1;
}