Skip to content

Instantly share code, notes, and snippets.

View ben-heath's full-sized avatar

ben-heath

View GitHub Profile
@ben-heath
ben-heath / gravity-form-merge-tag-cpt-get-embedded-post-cat.php
Created June 1, 2016 03:29
Gravity Form Merge tag for getting embedded post's category (of custom post type)
<?php
// merge tag for Job Application Category
add_action( 'gform_admin_pre_render', 'sls_add_merge_tags' );
function sls_add_merge_tags( $form ) {
?>
<script type="text/javascript">
gform.addFilter('gform_merge_tags', 'add_merge_tags');
function add_merge_tags(mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option){
mergeTags["custom"].tags.push({ tag: '{embededPostCat}', label: 'Embeded Post Category' });
@ben-heath
ben-heath / run-when-in-view.js
Created August 1, 2016 15:59
Run code when a specific html element is visible on a page
var $findit = jQuery('#visualisation'); // element that needs to be in view for thing to happen
function Scrolledit() {
$findit.each(function() {
var $section = jQuery(this),
finditOffset = $section.offset(),
finditTop = finditOffset.top,
finditBottom = $section.height() + finditTop,
scrollTop = jQuery(document).scrollTop(),
visibleBottom = window.innerHeight,
@ben-heath
ben-heath / display-posts-by-author-subscription-level.php
Created December 13, 2016 03:29
Restricting Display Posts shortcode posts to only show posts by Authors with specific WooCommerce Subscription
<?php
// This is dependant on Display Posts Shortcode plugin - https://wordpress.org/plugins/display-posts-shortcode/
// Alst dependant on WooCommerce Subscriptions Plugin - https://woocommerce.com/products/woocommerce-subscriptions/
// Adding the Author Subscription Level filter to Display Posts shortcode
function be_display_posts_shortcode_exclude_posts( $args, $atts ) {
if( isset( $atts['platinum'] ) ) {
$blogusers = get_users(); // get all users
$platinumUsers = array();
@ben-heath
ben-heath / respondo-bootstrap-modal-shortcode.php
Created May 2, 2017 13:42
Example Respondo Bootstrap modal shortcode
<?php
/* Bootstrap Docs:
* http://getbootstrap.com/javascript/#modals
* Lots of options could be added as attributes in the shortcode. The attached code is just the pieces I needed at the time.
* This is the simple shortcode:
* [sls-modal id="modal-1" header_text="HEADER TITLE HERE"]
* CONTENT HERE
* [/sls-modal]
* One thing that should be changed, is to allow for other respondo shortcode to be used within the content part.
* I hadn't shorted that out yet.
@ben-heath
ben-heath / link-and-scroll-to-tab.js
Created September 5, 2017 16:44
Link to specific tab on different page (or same page)
@ben-heath
ben-heath / animated-counter-intersectionObserver.js
Created February 23, 2018 23:21
Makes numbers animate from a number to another number (using IntersectionObserver API)
jQuery(document).ready(function(){
//jQuery('#rs-fullwidth-helper1').before('<p style="color:black;">testing4</p>');
function countUp() {
jQuery('.counter').each(function() {
var counter = jQuery(this),
countTo = counter.attr("data-count");
jQuery({ countNum: counter.text()}).animate({
countNum: countTo
@ben-heath
ben-heath / bootstrap-2-modal.php
Created March 16, 2018 14:36
This code works with bootstrap 2, and fixes the show/hide behavior experienced with Respondo if following normal Bootstrap documentation
# Trigger button/link
# Must use the 'onClick' method to target the modal, rather than 'data-target'
<a href="javascript:void(0);" id="login-pop-trigger" onClick="jQuery(\'#login-popup\').modal();" role="button" data-toggle="modal"><i class="fas fa-user-plus" aria-hidden="true"></i> Login</a>
# Simple Modal
<div id="login-popup" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-body">
<p>You are about to delete this Page, this is irreversible.</p>
</div>
</div>
@ben-heath
ben-heath / shortcode-list-cpt-posts.php
Created April 11, 2018 15:25
Shortcode list CPT posts
<?php
add_shortcode( 'video-testimonials', 'sls_video_testimonial_short_code' );
function sls_video_testimonial_short_code( $atts ) {
ob_start();
$query = new WP_Query( array(
'post_type' => 'video-testimonial',
'posts_per_page' => 4,
'order' => 'ASC',
'orderby' => 'title',
@ben-heath
ben-heath / reorder-html-by-data-attribute.php
Created April 11, 2018 21:51
Reorder html elements by data attribute using JS
<script>
/*
* This simple script will take multiple html elements, like a group of <li> or <span> or anything,
* and reorder them by the data attribute.
* Example:
* The script will reorder this:
* <span data-test="1">Number 1</span>
* <span data-test="4">Number 2</span>
* <span data-test="3">Number 3</span>
* <span data-test="2">Number 4</span>
@ben-heath
ben-heath / sls-countdown-flipper-clock.php
Created August 31, 2018 14:15
WordPress Shortcode countdown clock using FlipClock.js
<?php
/* Need to include flipclock.js's css and js files. Instructions found on their github page
* http://flipclockjs.com
*
*/
// Flipper countdown function
function sls_flipper_countdown($atts){
// Attributes - For the End Date
extract( shortcode_atts(
array(