Skip to content

Instantly share code, notes, and snippets.

View lkoudal's full-sized avatar

Lars Koudal lkoudal

View GitHub Profile
@lkoudal
lkoudal / wpa-clean-header.php
Created July 21, 2021 16:20 — forked from Auke1810/wpa-clean-header.php
create a clean wordpress header and remove unnecessary clutter.
<?php
/*
Plugin Name: wordpress assist clean header
Plugin URI: http://www.wordpressassist.nl/
Description: Remove shortlink hook
Version: 1.0
Author: AukeJomm
Author URI: http://www.aukejongbloed.nl
*/
@lkoudal
lkoudal / wp_gtm_data_layer_gravity_forms.php
Created February 22, 2021 13:42 — forked from tammalee/wp_gtm_data_layer_gravity_forms.php
[WP] GTM data layer push for Gravity Forms
<?
/**
* GTM data layer push for gravity forms contact form
*/
/**
* Pushes a submission variables to the GTM dataLayer
* Also pushes the event label for use in GTM tracking
* @param Array $entry the data submitted with the form
* @param Array $form Form data
* @return null
# Install brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install composer
brew install homebrew/php/composer
### PHPCS
composer global require "squizlabs/php_codesniffer=*"
# Add to your .bash_profile
@lkoudal
lkoudal / lazy-elementor-background-images.php
Created November 20, 2020 16:44 — forked from jrevillini/lazy-elementor-background-images.php
lazyload elementor background images
<?php
// NEWS!!! NEWS!!! **** FEBRUARY 2020 //
// I rolled this code into a plugin!
// Download plugin Lazy Load Background Images for Elementor. Link is in comments below.
// Or go to https://james.revillini.com/projects/
// if you don't want another plugin, the code below works (last time I checked)
@lkoudal
lkoudal / functions.php
Created October 27, 2020 22:24 — forked from thetwopct/functions.php
Preload any footer JS files in the header
/**
* Preload any footer JS files in the header
*
* originally from: https://macarthur.me/posts/preloading-javascript-in-wordpress
*/
add_action('wp_head', function () {
global $wp_scripts;
@lkoudal
lkoudal / count_different_meta_key
Last active July 14, 2020 21:11
Count how many different kind of meta_key's there are - and how many there are of each.
SELECT meta_key, COUNT( * ) c FROM `wp_postmeta` GROUP BY meta_key ORDER BY `c` ASC
@lkoudal
lkoudal / secure-plugin.js
Last active April 17, 2020 22:09
Using nonce from WordPress plugin in JavaScript file
jQuery(document).ready(function($) {
$.ajax({
url: ajaxurl, // WP variable, contains URL pointing to admin-ajax.php
type: 'POST',
data: {
'action':'get_custom_data',
'_ajax_nonce':plugin_ajax_object.nonce,
'user_data':'Some input from a user'
},
success: function( response ) {
@lkoudal
lkoudal / secure-plugin.php
Last active April 17, 2020 22:09
Check and verify a nonce in WordPress plugin from JavaScript code
<?php
add_action('wp_ajax_get_custom_data', 'get_custom_data');
function get_custom_data() {
// Ready for the magic to protect your code?
check_ajax_referer('secure-plugin-nonce');
/* That's it - the check_ajax_referer function verifies the nonce is correct or it dies and stops code execution if it fails.
@lkoudal
lkoudal / secure-plugin.php
Last active April 17, 2020 21:58
Using nonces in WordPress plugin
<?php
add_action('wp_enqueue_scripts', 'load_my_plugin_script');
function load_my_plugin_script() {
// Register the script with all details and ensures it is loaded after jQuery
wp_register_script('secure-plugin', plugin_dir_url( __FILE__ ). 'js/secure-plugin.js', array( 'jquery' ) );
// Here happens the magic, we add some details to an object that we can later reference and read from in our JS code.
wp_localize_script(
@lkoudal
lkoudal / freemius-checkout-button.markdown
Last active April 11, 2022 20:28
Freemius checkout button

Freemius checkout button

Inspired by James Kemp's interface - This example has tabs for monthly, annual and lifetime billing cycles.

You can choose between 1, 10 and 50 sites - each with different pricing.

There is a place to enter coupon code + user can choose between big buy button or a 7-day trial.

A Pen by Lars Koudal on CodePen.