Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View michelmany's full-sized avatar

Michel Many michelmany

View GitHub Profile
@michelmany
michelmany / function.php
Created January 10, 2024 02:11
WordPress remove_default_category (uncategorized)
function remove_default_category($ID, $post) {
//get all categories for the post
$categories = wp_get_object_terms($ID, 'category');
//if there is more than one category set, check to see if one of them is the default
if (count($categories) > 1) {
foreach ($categories as $key => $category) {
//if category is the default, then remove it
if ( $category->name === "Uncategorized") {
@michelmany
michelmany / parse.js
Created May 24, 2022 17:01
JSON.parse remove invalid string caracter with regex
const newString = JSON.parse(str.replace(/(\{|,)\s*(.+?)\s*:/g, '$1 "$2":'))
@michelmany
michelmany / carousel_component.html
Created November 5, 2021 09:57
Alpine.js Carousel Component
@michelmany
michelmany / accordion_component.html
Created November 5, 2021 09:55
Alpine.js Accordion Component
<div x-data="{ active: 1 }" class="space-y-4">
<div x-data="{
id: 1,
get expanded() {
return this.active === this.id
},
set expanded(value) {
this.active = value ? this.id : null
},
}" role="region" class="border border-black">
@michelmany
michelmany / main.yml
Created October 5, 2021 17:48
WordPress Theme Deployment with Github Action and rsync
# This is a basic workflow to help you get started with Actions
name: Build & Deploy to Staging (DO)
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ staging ]
pull_request:
@michelmany
michelmany / gist:21cc831551ac9cc222029816a915dba4
Created July 13, 2021 15:09 — forked from martinsanne/gist:72f48bad22d99032ba0e
WordPress ACF Multisite location rule
<?php
/**
*
* Adds location rule to target specific sites in a WordPress Multisite environment
* http://www.advancedcustomfields.com/resources/custom-location-rules/
*
*/
function acf_location_rule_type_blog( $choices ) {
@michelmany
michelmany / functions.php
Created November 4, 2020 21:02
How to Change WooCommerce “Select Options” Text
add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
global $product;
if ( $product->is_type( 'variable' ) ) {
$text = $product->is_purchasable() ? __( 'Custom options text', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
}
return $text;
}, 10 );
@michelmany
michelmany / ordinal.php
Created October 1, 2020 15:00
Display numbers with ordinal suffix in PHP
/**
* Set Ordinal Numbers
*
* @param [type] $number
* @return void
*/
function ordinal($number) {
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
if ((($number % 100) >= 11) && (($number%100) <= 13))
@michelmany
michelmany / wp-config.php
Created July 8, 2020 19:52
Cloudflare WordPress SSL
# It will solve the too many redirects issue
define('FORCE_SSL_ADMIN', true);
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS']='on';
@michelmany
michelmany / recaptchav3.css
Created May 25, 2020 19:14
Set the ReCaptcha v3 to the left of the screen.
.grecaptcha-badge {
width: 70px !important;
overflow: hidden !important;
transition: all 0.3s ease !important;
left: 4px !important;
}
.grecaptcha-badge:hover {
width: 256px !important;
}