Skip to content

Instantly share code, notes, and snippets.

Avatar

Thierry Pigot thierrypigot

View GitHub Profile
@thierrypigot
thierrypigot / functions.php
Created May 31, 2021
Redirect uploads folder when import single website in WordPress multisite
View functions.php
<?php
/**
* 404
*/
function wearewp_redirect_404_uploads() {
if ( is_404() && preg_match( '/uploads/i', $_SERVER["REQUEST_URI"] ) ) {
$blog_id = get_current_blog_id();
$new_url = home_url( str_replace( '/uploads/', '/uploads/sites/'. $blog_id .'/', $_SERVER["REQUEST_URI"] ) );
wp_safe_redirect( $new_url, 301 );
exit;
View wp-class-eric.php
<?php
class Eric{
function __construct(){
add_action( 'init', [ $this, 'remove_category_for_posts' ] );
add_action( 'init', [ $this, 'add_category_for_pages' ] );
add_filter( 'register_taxonomy_args', [ $this, 'rename_category' ], 10, 3);
add_action( 'pre_get_posts', [ $this, 'category_archives' ] );
}
View grid-media.css
/* Grille avec media queries */
.grids {
max-width: 1140px;
margin: 0 auto;
display: grid;
grid-gap: 0 1rem;
grid-template-columns: repeat(1, 1fr);
}
@thierrypigot
thierrypigot / demo.html
Created Jan 12, 2021
Automatically Adjust iFrame Height According to its Contents Using JavaScript
View demo.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Auto Adjust iFrame Height Based on Content</title>
<style>
iframe{
width: 100%;
border: 2px solid #ccc;
}
@thierrypigot
thierrypigot / antispambot-mailto-menuLink.php
Created Jul 31, 2020
WordPress : auto add Antispambot on mailto email address inside menu links
View antispambot-mailto-menuLink.php
View gist:80a825e8010e74311c1bbafc77cedea1
INITIALISATION
==============
load wp-config.php
set up default constants
load wp-content/advanced-cache.php if it exists
load wp-content/db.php if it exists
connect to mysql, select db
load object cache (object-cache.php if it exists, or wp-include/cache.php if not)
load wp-content/sunrise.php if it exists (multisite only)
@thierrypigot
thierrypigot / wearewp-cpt-glance.php
Created Sep 16, 2019
Custom post type counts in 'Right now' Dashboard widget
View wearewp-cpt-glance.php
<?php
/*
Plugin Name: Custom post type counts
Description: Custom post type counts in 'Right now' Dashboard widget
Plugin URI: https://www.wearewp.pro
Version: 1.0
Author: WeAre[WP]
Author URI: https://www.wearewp.pro
*/
@thierrypigot
thierrypigot / wpml-config.xml
Created Aug 23, 2019
Beaver Builder theme cutomizer translation with Polylang and WPML
View wpml-config.xml
<wpml-config>
<admin-texts>
<key name="theme_mods_{THEMENAME}">
<key name="fl-topbar-col1-text" />
<key name="fl-logo-image-retina" />
<key name="fl-logo-image" />
</key>
</admin-texts>
</wpml-config>
@thierrypigot
thierrypigot / functions.php
Last active Jul 15, 2019
Defer WordPress javascript
View functions.php
<?php
// Show javascript handle
add_filter( 'script_loader_tag', 'wearewp_add_script_handle', 10, 3 );
function wearewp_add_script_handle( $tag, $handle, $src ) {
return str_replace( '<script', sprintf(
'<script data-handle="%1$s"',
esc_attr( $handle )
), $tag );
}
@thierrypigot
thierrypigot / waw-publishing.php
Last active May 21, 2019
Use this script to publish future post by server cron. USE: {site OR sub-site URL}/waw-publishing.php
View waw-publishing.php
<?php
/**
Description: Use this script to publish future post by server cron. USE: {site OR sub-site URL}/waw-publishing.php
Author: WeAre[WP]
Author URI: https://www.wearewp.pro
Version: 1.0
CRON
wget -O /dev/null https://site-A.com/waw-publishing.php