Skip to content

Instantly share code, notes, and snippets.


Gal Baras galbaras

View GitHub Profile
View gbol_add_rounded_sale_event.php
* Since Google Analytics only allows integers as event values, Monster Insights multiplies the value by 100.
* This makes it difficult to use sale events for goal tracking and adding their values to other goals.
* This function adds a custom event with the sales value rounded, which should be close enough in most cases.
* Requires WooCommerce (version >= 3.0) and Monster Insights (free or premium) to be active.
add_filter( 'monsterinsights_mp_api_call', 'gbol_add_rounded_sale_event' );
function gbol_add_rounded_sale_event( $body ) {
View expand_shortcodes_in_excerpts.php
/* Allow Easy Testimonials and Visual Composer shortcodes in excerpts */
add_filter( 'strip_shortcodes_tagnames', 'gbol_allow_shortcodes' );
function gbol_allow_shortcodes( $tags_to_remove ) {
$allowed_shortcodes = array( 'random_testimonial', 'single_testimonial', 'testimonials', 'testimonials_cycle', 'testimonials_grid',
'vc_row', 'vc_column', 'vc_column_text' );
foreach( $allowed_shortcodes as $tag ) {
if ( $key = array_search( $tag, $tags_to_remove ) ) {
galbaras / insert_ad_after_block.php
Last active Nov 22, 2017
Insert Google ad after specific top-level text block in WordPress post
View insert_ad_after_block.php
* This code is for WordPress and should be used in functions.php of the active theme.
* Before using it, replace "ADVERTISER ID" with your own advertiser ID and "SLOT ID" with your own slot ID
* (you can get both in Google AdSense). For best results, use a reponsive ad unit.
* If your posts contain "pre", "noscript" or some other type of HTML block, add them to $block_tags.
* You can change the insertion point by changing $after_block.
galbaras / functions.php
Created Sep 1, 2015
Add a WooCommerce attribute (minimum quantity) to a Contact Form 7 form. Can be easily adapted to other attributes, as well as product meta, terms, etc
View functions.php
// Save product_quantity_field.php in your active theme directory, then
// add this line to your functions.php file to include it in the theme
include( get_stylesheet_directory() . '/product_quantity_field.php' );
galbaras / no_urls_allowed.php
Last active Aug 8, 2022
Function to invalidate Contact Form 7 input, unless the fields is of type "url" or has "url" in its name, i.e. it is meant for URLs
View no_urls_allowed.php
add_filter( 'wpcf7_validate_text', 'no_urls_allowed', 10, 3 );
add_filter( 'wpcf7_validate_text*', 'no_urls_allowed', 10, 3 );
add_filter( 'wpcf7_validate_textarea', 'no_urls_allowed', 10, 3 );
add_filter( 'wpcf7_validate_textarea*', 'no_urls_allowed', 10, 3 );
function no_urls_allowed( $result, $tag ) {
$tag = new WPCF7_Shortcode( $tag );
$type = $tag->type;
$name = $tag->name;
galbaras / adminbartoggle
Last active Aug 29, 2015
Toggling the display of the WordPress Admin Bar (wpadminbar)
View adminbartoggle
The WordPress admin bar can sometimes get in the way of checking what a site looks like
while being logged in, so it's convenient to hide it occasionally.
To do this, we need a CSS class and some jQuery code, which toggles the admin bar display
when pressing Shift-A.
The CSS can be added to the theme's normal stylesheet. The PHP/jQuery code can be added
into footer.php or included within an action in functions.php.
* The code was adapted from the Bottom Admin Bar plugin.
galbaras / gist:efec7adc266db3b40699
Created Jul 2, 2014
Embedded video notice for emailed feeds
View gist:efec7adc266db3b40699
function add_rss_video_embed_notice( $html, $url, $attr, $post_id ) {
if (!is_feed()) { // No need to change anything
return $html;
$permalink = get_permalink( $post_id );
$notice = '<br /><small>If you cannot see a video, <a href="' . $permalink . '">view this post online</a></small>';
return $html . $notice;
galbaras / gist:6ad566fa9fd7dd8de1d5
Last active May 29, 2019
Make special WooCommerce pages "noindex,follow" when using Yoast SEO
View gist:6ad566fa9fd7dd8de1d5
function woo_seo_noindex_special_pages () {
global $post;
$woocommerce_pages = array('cart', 'checkout', 'order-received', 'order-tracking',
'my-account', 'logout', 'lost-password', 'mijireh-secure-checkout');
$slug = get_post($post)->post_name;
if (in_array($slug, $woocommerce_pages)) {
echo '<meta name="robots" content="noindex,follow"/>' . "\n";