Skip to content

Instantly share code, notes, and snippets.

View cubehrends's full-sized avatar
🏠
Working from home

Christian Behrends cubehrends

🏠
Working from home
View GitHub Profile
<?php
/* Shortcode to Display Markers in functions.php
=============================================================== */
function cmm_markers_shortcode( $atts, $content = null ) {
$args = array( 'post_type' => 'marker',
'posts_per_page' => -1,
'post_status' => 'publish',
'suppress_filters' => true
);
$markers = new WP_Query( $args );
<?php
/* Enqueuing Scripts in functions.php
=============================================================== */
function cmm_scripts() {
wp_enqueue_script( 'cmm-js', get_stylesheet_directory_uri() . '/js/cmm.js', array('jquery'), '1.0', true);
}
add_action( 'wp_enqueue_scripts', 'cmm_scripts' );
var gaProperty = 'UA-XXXXXXXX-Y';
var disableStr = 'ga-disable-' + gaProperty;
// checking for opt-out cookie on document and applying to window if set
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
}
// user is opting out, setting cookie on document, window and alerting success
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;
<script>
(function( $ ) {
$( '.fusion-logo-link > img' ).attr('src', '/wp-content/uploads/2018/01/special-logo.png').attr('srcset', '/wp-content/uploads/2018/01/special-logo.png 1x, /wp-content/uploads/2018/01/special-logo.png 2x').attr('retina_logo_url', '/wp-content/uploads/2018/01/special-logo.png');
})( jQuery );
</script>
@cubehrends
cubehrends / functions.php
Last active May 1, 2018 08:24
Prevent Divi from loading Fonts from Google for GDPR-compliance
<?php
/* Prevent Google Fonts from loading
=============================================================== */
function prevent_loading_fonts() {
remove_action('wp_enqueue_scripts', 'et_divi_load_fonts');
}
add_action( 'init', 'prevent_loading_fonts', 20 );
function et_builder_get_google_fonts() { return array(); }
function et_get_google_fonts() { return array(); }
@cubehrends
cubehrends / script.js
Last active May 11, 2018 08:00
GDPR Consented Loading from GitHub for WordPress Page Builders like Divi, Elementor, Gutenberg etc. Learn more at https://webdevtrust.com/gdpr-consent-loading-page-builder/
<script id="gist0">
(function( $ ) {
if ( has_consent( 'github' ) ){
$.getJSON( 'https://gist.github.com/cubehrends/1f316da01358e85f3592742327f0d83a.json?callback=?', function( data ) {
$('#gist0').parent().html( $( data.div ) ).append('<link rel="stylesheet" href="' + data.stylesheet + '">')
} )
} else {
@cubehrends
cubehrends / functions.php
Last active May 18, 2018 11:47
How to customize the Comment Form Cookies Consent Label in WordPress 4.9.6
<?php
/* the code below goes into your child themes functions.php
=============================================================== */
function customize_comment_form_cookies_consent_label( $translated, $original, $domain ) {
$strings = array(
'Save my name, email, and website in this browser for the next time I comment.' => '=> YOUR CUSTOMIZED TEXT GOES HERE <='
);
if ( ! empty( $strings[$original] ) ) {
@cubehrends
cubehrends / lang.php
Last active September 18, 2018 15:44
<?php
if ( $_GET ) {
$lang = set_lang( key($_GET) );
} else if ( isset($_COOKIE['lang']) ) {
$lang = $_COOKIE['lang'];
} else {
$lang = set_lang( substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) );
}
function set_lang( $l ) {
@cubehrends
cubehrends / functions.php
Last active September 28, 2018 14:23
WordPress GDPR Comments w/ Polylang via Child Theme
<?php
function register_pll_strings() {
if( !function_exists( 'pll_register_string' ) ) return; // go away if polylang not active
pll_register_string('Policy Accept', 'I read your', 'CommentForm');
pll_register_string('Privacy Policy', 'Privacy Policy', 'CommentForm');
pll_register_string('Policy Page', 'privacy', 'CommentForm');
pll_register_string('Error', 'ERROR', 'CommentForm');