Skip to content

Instantly share code, notes, and snippets.

View tankbar's full-sized avatar

Tankbar tankbar

View GitHub Profile
@tankbar
tankbar / wp-google-tag-manager
Last active January 23, 2024 11:17
Add Google Tag Manager in WordPress with hooks and actions
<?php
/* ADD GTM TO HEAD AND BELOW OPENING BODY */
add_action('wp_head', 'google_tag_manager_head', 20);
function google_tag_manager_head() { ?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
@tankbar
tankbar / wc-bcc-email-order-completed
Last active July 4, 2017 11:26
WooCommerce - Send a BCC e-mail order copy when order status changes to completed
/* BCC Email for orders completed for WooCommerce version 2.3 and above */
add_filter( 'woocommerce_email_headers', 'es_headers_filter_function', 10, 3);
function es_headers_filter_function( $headers, $id, $object ) {
if ($id == 'customer_completed_order') {
$headers .= 'BCC: Trustpilot <xxxxx@invite.trustpilot.com>' . "\r\n";
}
return $headers;
}
@tankbar
tankbar / _media-queries.scss
Last active June 23, 2016 09:50
Media Queries helper in your SCSS project
// These mixins make media queries a breeze with SCSS.
// The media queries from mobile up until desktop all trigger at different points along the way.
// This helper is focused on mobile first. You style your block as it whould appear in mobile and then add CSS for how it scales up.
//
// Example
// .block {
// height: 250px;
//
// @include MQ(M) {
// height: 300px;
@tankbar
tankbar / wc-dynamic-tracking-code-thank-you-page
Created June 27, 2016 11:26
Dynamic Purchase Tracking Code - Thank you page
// Dynamic Purchase Tracking Code - Thank you page
function thankyou_tracking( $order_id ) {
$order = new WC_Order( $order_id );
$order_total = $order->get_total();
$order_nr = $order->get_order_number();
?>
<!-- Tracking Code -->
<?php echo $order_nr; ?>
<?php echo $order_total; ?>
@tankbar
tankbar / wc-replace-breadcrumbs-with-yost
Created June 27, 2016 11:44
Remove default WooCommerce breadcrumbs and add Yoast ones instead
// Remove default WooCommerce breadcrumbs and add Yoast ones instead
remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
add_action( 'woocommerce_before_main_content','my_yoast_breadcrumb', 20, 0);
if (!function_exists('my_yoast_breadcrumb') ) {
function my_yoast_breadcrumb() {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
}
}
@tankbar
tankbar / wc-strip-unwanted-product-categories-loop-output
Last active June 27, 2016 12:43
Strip unwanted product categories in categories loop on single product page and/or woocommerce loop
//Strip unwanted product categories in categories loop on single product page and/or woocommerce loop
//Add this manually to your wanted hook or filter
function list_clean_categories() {
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
$unwanted_cat_slugs = array();
//Example: $unwanted_cat_slugs[] = "campaign-summer";
$unwanted_cat_slugs[] = "xxx";
$unwanted_cat_slugs[] = "yyy-yyy";
@tankbar
tankbar / wc-facebook-tracking-pixel-thank-you-page
Created June 27, 2016 14:23
Facebook tracking pixel on Thank you page
// Facebook tracking pixel on Thank you page
function fb_pixeltracking( $order_id ) {
$order = new WC_Order( $order_id );
$order_total = $order->get_total();
?>
<!-- Facebook Conversion Code -->
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
@tankbar
tankbar / _typography.scss
Last active August 23, 2016 08:37
CSS default font-smoothing for typography.scss
// These text rendering optimization settings are default on all our sites from 2016.
body {
-moz-font-smoothing: antialiased;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
/* Recommended default font-size and line-height */
line-height: 1.5;
font-size: 16px;
@tankbar
tankbar / _cookie.scss
Last active July 4, 2017 11:25
Styling for WordPress plugin cookie-notice
@tankbar
tankbar / gravity-forms-ajax-spinner
Last active September 14, 2016 12:25
Change the Default Gravity Forms AJAX Spinner - If you want to change the default Gravity Forms AJAX spinner, Gravity Forms provides us with a filter to do so: gform_ajax_spinner_url. Paste the following code into your installed and activated custom snippets plugin.
add_filter( 'gform_ajax_spinner_url', 'cwwp_custom_gforms_spinner' );
/**
* Changes the default Gravity Forms AJAX spinner.
*
* @since 1.0.0
*
* @param string $src The default spinner URL
* @return string $src The new spinner URL
*/
function cwwp_custom_gforms_spinner( $src ) {