Skip to content

Instantly share code, notes, and snippets.

View Asikur22's full-sized avatar
💜
Web Developer | In Love with WordPress

Asiqur Rahman Asikur22

💜
Web Developer | In Love with WordPress
View GitHub Profile
@Asikur22
Asikur22 / gulpfile.js
Created June 30, 2024 19:16
WP Hot Reload with Gulp file
/**
*
* How to use this file
*
* Step 1: Ensure Gulp CLI is installed globally
* npm install gulp-cli -g
* Step 2: Install BrowserSync and Gulp as a local development dependency for the project.
* npm install browser-sync gulp --save-dev
* Step 3: Save this file to the directory and edit where appropriate
* Step 4: Type gulp in the command line to initiate BrowserSync
@Asikur22
Asikur22 / package.json
Created June 30, 2024 19:07
WordPress hot reload with browser-sync
{
"name" : "wp-hot-reloader",
"version" : "1.0",
"description" : "WordPress hot reload with browser-sync",
"author" : "Asiqur Rahman <asiq.webdev@gmail.com> (https://www.asique.net/)",
"license" : "GPL-2.0-or-later",
"config" : {
"host" : "wp.local",
"port" : "8080"
},
@Asikur22
Asikur22 / hooks.php
Created February 29, 2024 01:29
Preconnect Custom CDN
add_filter( 'wp_resource_hints', 'preconnect_custom_cdn', 99, 2 );
function preconnect_custom_cdn( $urls, $relation_type ) {
if ( $relation_type == 'preconnect' ) {
$urls[] = [
'href' => 'https://fonts.googleapis.com',
];
$urls[] = [
'href' => 'https://fonts.gstatic.com',
'crossorigin' => true
@Asikur22
Asikur22 / hooks.php
Created February 6, 2024 19:29
WooCommerce Change My Account Endpoint Document Title
/**
* Filters document title.
*
* @param array $title The document title parts.
*
* @return array
*/
function wp98_endpoint_document_title( $title ) {
if ( is_wc_endpoint_url( 'orders' ) ) {
$title['title'] = __( 'My Order Custom Document Title', 'woocommerce' );
@Asikur22
Asikur22 / functions.php
Created December 1, 2023 10:59
WordPress Load Next Post with AJAX
add_action( 'wp_footer', function () {
if ( is_single() ) {
?>
<script>
jQuery( function ( $ ) {
var gl_load_spinner = $( '#gl-load-more-spinner' );
var gl_next_post_link = $( '.elementor-post-navigation__next.elementor-post-navigation__link a' ).attr( 'href' );
var canBeLoaded = true;
const bottomOffset = 2000;
@Asikur22
Asikur22 / script.js
Created July 30, 2023 04:03
JS Date Format
function currentServerDate() {
let dateWithTimeZone = new Date().toLocaleString( "en-US", {timeZone: "<?php echo wp_timezone_string(); ?>"} );
let d = new Date( dateWithTimeZone );
var year = d.getFullYear();
var month = (
"00" + (
d.getMonth() + 1
)
).slice( - 2 );
@Asikur22
Asikur22 / hooks.php
Created July 30, 2023 00:06
ACF Default Value
add_filter( 'acf/load_field/name=booking_calendar_feed_link', function ( $field ) {
$field['default_value'] = 'Default Value';
$field['disabled'] = 1;
return $field;
} );
@Asikur22
Asikur22 / woo.php
Last active May 29, 2023 08:54
Remove Shipping Method/Rate based on Checkout Fields
add_filter( 'woocommerce_package_rates', function ( $rates ) {
if ( isset( $_POST['post_data'] ) ) {
parse_str( $_POST['post_data'], $post_data );
if ( isset( $post_data['billing_custom_field'] ) ) {
switch ( $post_data['billing_custom_field'] ) {
case 'Jeg_henter_selv':
unset( $rates['local_pickup:5'] );
break;
case 'Levering_til_adresse':
@Asikur22
Asikur22 / functions.php
Created May 7, 2023 18:25
Remove Filter Hook Forcefully
function remove_obj_filter_forcefully( $tag, $callback, $priority = 10 ) {
global $wp_filter;
$my_filter = $wp_filter[ $tag ];
if ( isset( $my_filter ) ) {
$callbacks = $my_filter->callbacks;
if ( ! empty( $callbacks ) ) {
foreach ( (array) $callbacks[ $priority ] as $filter_callback ) {
if ( in_array( $callback, $filter_callback['function'] ) ) {
$my_filter->remove_filter( $tag, $filter_callback['function'], $priority );
@Asikur22
Asikur22 / customroutes.php
Created December 20, 2022 09:52 — forked from samhernandez/customroutes.php
A simple class to add custom routes to Wordpress.
<?php
/**
* NOTE: This gist is very old. You might want to check out recent forks
* like this one: https://github.com/Alexlytle/Wordpress_custom_route/blob/main/Wordpress_Custom_route.php
* (thanks @Alexlytle) If you have an improvement to this gist, please
* post a link in a comment for others who might benefit. Thanks!
*
* A class to create simple custom routes.
*