Skip to content

Instantly share code, notes, and snippets.

<?php
/*
Check if protocol is https
Nb: port 443 does not guarantee connection is encrypted
http://stackoverflow.com/questions/1175096/how-to-find-out-if-you-are-using-https-without-serverhttps#answer-2886224
*/
function isSecure() {
return
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|| $_SERVER['SERVER_PORT'] == 443;
@larsmqller
larsmqller / gist:0172157a2737dd8755f7
Created June 17, 2015 16:15
Load translation files from your child theme instead of the parent theme
function my_child_theme_locale() {
load_child_theme_textdomain( 'my_child_theme', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'my_child_theme_locale' );
@larsmqller
larsmqller / countCSSRules.js
Created October 6, 2015 12:30 — forked from psebborn/countCSSRules.js
Count the number of rules and selectors for CSS files on the page. Flags up the >4096 threshold that confuses IE
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {
@larsmqller
larsmqller / my-plugin-snippet.php
Created November 4, 2015 12:02 — forked from szbl/my-plugin-snippet.php
How I auto-include my library of "controllers" in a theme/plugin.
<?php
// include all PHP files in ./lib/ directory:
foreach ( glob( dirname( __FILE__ ) . '/lib/*.php' ) as $file )
include $file;
@larsmqller
larsmqller / functions.php
Created January 9, 2016 17:33
WordPress Language translation, stuff i forget.
*/
https://localise.biz/help/wordpress/loading-translations
"If WordPress fails to find a MO file at this exact location, it will then look in the global languages directory"
So in short, WordPress will look in only two places for a theme's MO file:
{absolute_path}/{locale}.mo
wp-content/languages/themes/{domain}-{locale}.mo
e.g. for twentyfourteen's French translations:
@larsmqller
larsmqller / header.php
Created March 2, 2016 22:07 — forked from retlehs/header.php
Sage header template for Bootstrap top navbar component
<?php
// This file assumes that you have included the nav walker from https://github.com/twittem/wp-bootstrap-navwalker
// somewhere in your theme.
?>
<header class="banner navbar navbar-default navbar-static-top" role="banner">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only"><?= __('Toggle navigation', 'sage'); ?></span>
// Login log out functionality in menu, add stuff to menu
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'top_nav') {
$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'top_nav') {
$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
}
return $items;
fl.videoLog = {
init: function () {
console.log('#asdf');
var self = this;
$("video[data-ga-logging-name]").on("play", function () {
var gaLoggingName = this.dataset.gaLoggingName;
fl.videoLog.vars.trackingStatus = true;
init: function () {
console.log('#asdf');
var self = this;
$("video[data-ga-logging-name]").on("play", function () {
var gaLoggingName = this.dataset.gaLoggingName;
fl.videoLog.vars.trackingStatus = true;
@larsmqller
larsmqller / wootriggersCartCheckout.js
Created September 22, 2018 14:50
Woocommerce cart and checkout triggers
//Cart
//https://github.com/woocommerce/woocommerce/blob/d30c54ef846b086b96278375b71f7c379d9aa8e8/assets/js/frontend/cart.js
$( document.body ).on( 'update_checkout', function(){});
$( document.body ).on( 'updated_cart_totals', function(){});
$( document.body ).on( 'updated_wc_div', function(){});
$( document.body ).on( 'updated_shipping_method', function(){});
$( document.body ).on( 'applied_coupon', function(){});
$( document.body ).on( 'removed_coupon', function(){});
// Checkout