Skip to content

Instantly share code, notes, and snippets.

View goranseric's full-sized avatar

Goran Šerić goranseric

View GitHub Profile
@goranseric
goranseric / dom-routing.js
Created December 20, 2022 11:39 — forked from dotMastaz/dom-routing.js
DOM-Based Routing
/* ========================================================================
* DOM-based Routing
* Based on http://goo.gl/EUTi53 by Paul Irish
*
* Only fires on body classes that match. If a body class contains a dash,
* replace the dash with an underscore when adding it to the object below.
*
* .noConflict()
* The routing is enclosed within an anonymous function so that you can
@goranseric
goranseric / README.md
Created June 30, 2022 07:31 — forked from ControlledChaos/README.md
Add srcset and sizes attributes to Advanced Custom Fields image uploads.

ACF Responsive Images

WordPress Snippet

Adds the srcset and sizes attributes to ACF image uploads. Requires installation of the Advanced Custom Fields plugin.

NOTE: ACF image field must be set to return the ID.

NOTE: WordPress needs image sizes with equal aspect ratios in order to generate the srcset, and does not use srcset when images are added as "Full Size".

@goranseric
goranseric / Gravity Forms Get Credit Card Details
Created February 22, 2022 16:35 — forked from DeveloperWil/Gravity Forms Get Credit Card Details
Enables the credit card fields for Gravity Forms and provides a function to get the credit card details which are not available through the filter $form or $entry
//Turn on our credit card field for admin and front end
add_action("gform_enable_credit_card_field", "enable_creditcard");
function enable_creditcard($is_enabled){
return true;
}
//Email encoded card details when the form is submitted.
add_action('gform_after_submission', 'email_encoded_cc', 10, 2);
function email_encoded_cc($entry, $form) {
function get_creditcard_field($form){
$fields = GFCommon::get_fields_by_type($form, array("creditcard"));
@goranseric
goranseric / fbcbfwss.php
Created February 12, 2021 16:20 — forked from ocean90/fbcbfwss.php
WordPress Plugin: Filename-based cache busting for scripts/styles.
<?php
/**
* Plugin Name: Filename-based cache busting
* Version: 0.3
* Description: Filename-based cache busting for WordPress scripts/styles.
* Author: Dominik Schilling
* Author URI: http://wphelper.de/
* Plugin URI: https://dominikschilling.de/880/
*
* License: GPLv2 or later
@goranseric
goranseric / facetwp-selections-html.js
Created September 7, 2020 17:55 — forked from gayathrics/facetwp-selections-html.js
use this snippet to customize the facetwp selections html markup
//reference: \wp-content\plugins\facetwp\assets\js\front.js - Generate the user selections
wp.hooks.addAction('facetwp/loaded', function () {
// add custom code here
var selections = '';
jQuery.each(FWP.facets, function (key, val) {
if (val.length < 1 || 'undefined' === typeof FWP.settings.labels[key]) {
return true; // skip this facet
}
var choices = val;
@goranseric
goranseric / pluginLoaded.js
Created August 25, 2020 17:29 — forked from siamkreative/pluginLoaded.js
Check if a jQuery plugin is loaded. If not, load it using the $.getScript() function.
jQuery(document).ready(function ($) {
'use strict';
function initModal() {
$('.popup-youtube, .popup-vimeo, .popup-gmaps').magnificPopup({
disableOn: 700,
type: 'iframe',
mainClass: 'mfp-fade',
removalDelay: 160,
@goranseric
goranseric / functions.php
Created August 19, 2020 04:08 — forked from BronsonQuick/functions.php
Add a Gravity Forms validation filter to check default values
<?php
// Append the Gravity Forms ID to the end of the filter so that the validation only runs on this form
add_filter('gform_validation_1', 'custom_validation');
function custom_validation($validation_result){
$form = $validation_result["form"];
foreach($form['fields'] as &$field){
/* Check that the value of the field that was submitted. e.g. the name="input_1" that is generated by Gravity Forms */
if($_POST['input_1'] == "Your First Name"){
// set the form validation to false
$validation_result["is_valid"] = false;
@goranseric
goranseric / logging.php
Created August 5, 2020 04:51 — forked from richardW8k/logging.php
Logging statements for Gravity Forms.
<?php
add_filter( 'gform_pre_render', 'log_pre_render' );
function log_pre_render( $form ) {
GFCommon::log_debug( "log_pre_render(): \$form => " . print_r( $form, true ) );
return $form;
}
add_action( 'gform_pre_process', 'log_pre_process' );
function log_pre_process( $form ) {
@goranseric
goranseric / slugify.js
Created August 4, 2020 14:49 — forked from hagemann/slugify.js
Slugify makes a string URI-friendly
function slugify(string) {
const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;'
const b = 'aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------'
const p = new RegExp(a.split('').join('|'), 'g')
return string.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
@goranseric
goranseric / functions.php
Created May 11, 2020 05:50 — forked from sectsect/functions.php
Wordpress: Get the Deepest Terms. Supports Term order and Multiple Categories in Deepest hierarchy.
<?php
function get_the_terms_deepest($taxonomies, $term_order = false) {
$categories = get_the_terms(get_the_ID(), $taxonomies); // get all product cats for the current post
if($categories && !is_wp_error($categories)){ // wrapper to hide any errors from top level categories or products without category
if(count($categories) == 1){ // Case: Select only Category of Top Level. (Required: Activate Plugin Parent Category Toggler)
$return = $categories;
}elseif(count($categories) > 1){
$return = array();
foreach($categories as $category){ // loop through each cat
$children = get_categories(array('taxonomy' => $taxonomies, 'parent' => $category->term_id)); // get the children (if any) of the current cat