Skip to content

Instantly share code, notes, and snippets.

View daomapsieucap's full-sized avatar
🍰
Focusing

Dao daomapsieucap

🍰
Focusing
View GitHub Profile
@daomapsieucap
daomapsieucap / gtm-example.html
Created January 8, 2025 04:27
GTM code example
Script put on HEAD
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
@daomapsieucap
daomapsieucap / bulk_webpage_screenshots.py
Created May 4, 2023 09:54 — forked from ilovefreesw/bulk_webpage_screenshots.py
A Python-Selenium script to bulk take screenshots of webpage using headless Chrome by reading a text file full of URLs Tutorial: https://www.ilovefreesoftware.com/26/tutorial/how-to-take-full-page-screenshot-in-bulk-from-multiple-urls.html
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
from tqdm import tqdm
import time
lines = []
Links_File = r''
OP_DIR = r''
i = 1
@daomapsieucap
daomapsieucap / acf-populating-product-attributes.php
Created February 21, 2023 04:14
Populating Woocommerce product attributes to ACF
<?php
/**
* Populating Product Attributes
*/
add_filter('acf/load_field/name=woo_admin_attributes', 'dc_acf_product_attribute');
function dc_acf_product_attribute($field){
$product_taxonomies = get_taxonomies([
'_builtin' => false,
]);
@daomapsieucap
daomapsieucap / gravity-forms-localize-scripts.php
Created October 21, 2021 14:19
Override Gravity Forms Spinner by wp_localize_script (replace [my_spinner_url] with your spinner URL)
<?php
/**
* Gravity Form spinner
*/
add_action("gform_enqueue_scripts", "dc_gform_spinner", 10, 2);
function dc_gform_spinner($form, $is_ajax){
$new_spinner = array("spinnerUrl":"[my_spinner_url]");
wp_localize_script('gform_gravityforms', 'gf_global', $new_spinner);
}
@daomapsieucap
daomapsieucap / show_product_image_on_woo_thankyou.php
Last active October 16, 2021 04:34
Show Product Image in Thankyou and My Account View Order
<?php
add_filter('woocommerce_order_item_name', 'dc_product_image_on_thankyou_myacount', 10, 3);
function dc_product_image_on_thankyou_myacount($name, $item, $visible){
if(!$visible){
return $name;
}
if(!is_order_received_page() && !is_account_page()){
return $name;
}
@daomapsieucap
daomapsieucap / zip_source_code_upload.yml
Last active September 26, 2021 02:15
Release WordPress custom plugin with GitHub Action
name: 🚚 Create Archive
on: [ push ]
jobs:
web-deploy:
name: 🎉 Deploy
runs-on: ubuntu-latest
steps:
- name: 🚚 Get latest code
uses: actions/checkout@v2
@daomapsieucap
daomapsieucap / theme_plugin_requirements.php
Created September 24, 2021 08:32
Plugin Requirements for WordPress theme
<?php
/**
* Plugin Requirements
*/
add_action('admin_notices', 'dc_theme_dependencies');
function dc_theme_dependencies(){
if(!is_plugin_active('framework_plugin/framework_plugin.php')){
echo '<div class="error"><p>' . __('The current theme requires plugin [Your Plugin Name], please install and activate [Your Plugin Name] plugin', 'dc') . '</p></div>';
}
@daomapsieucap
daomapsieucap / wp_update_enqueued_resources.php
Last active September 23, 2021 15:17
Update enqueued resource in WordPress
<?php
/**
* Update enqueued resource in WordPress
*/
add_filter('script_loader_src', 'dc_update_resource_urls', 9999, 2);
function dc_update_resource_urls($src, $handle){
// check if it's my theme scripts and it's not the minified files
if(!is_admin() && strpos($handle, THEME_PREFIX) !== false && strpos($src, 'min.js') === false){
// do the replacement
$src = str_replace('.js', '.min.js', $src);
@daomapsieucap
daomapsieucap / functions.php
Created September 11, 2021 14:54
Remove image srcset
<?php
/**
* Remove image srcset
*/
add_filter('wp_calculate_image_srcset', 'dc_remove_srcset');
function dc_remove_srcset(){
return false;
}
@daomapsieucap
daomapsieucap / functions.php
Last active April 17, 2023 10:20
Delete orphaned files in wp-content/uploads that are not WordPress attachments
<?php
/**
* Delete orphaned files in wp-content/uploads that are not WordPress attachments
*/
add_action('dc_clean_orphaned_uploads', 'dc_clean_orphaned_uploads', 10, 0);
function dc_clean_orphaned_uploads(){
$uploads_dir = wp_upload_dir();
$search = $uploads_dir['basedir'];
$replace = $uploads_dir['baseurl'];