Skip to content

Instantly share code, notes, and snippets.

Avatar

Thierry Pigot thierrypigot

View GitHub Profile
@thierrypigot
thierrypigot / check-broken-link.php
Created Apr 25, 2022
Check for broken link with PHP
View check-broken-link.php
View functions.php
<?php
// [jour] => mardi
add_shortcode( 'jour', 'waw_shortcode_jour' );
function waw_shortcode_jour() {
return date_i18n('l');
}
// [mois] => mars
add_shortcode( 'mois', 'waw_shortcode_mois' );
function waw_shortcode_mois() {
@thierrypigot
thierrypigot / script.js
Created Jan 21, 2022
jQuery add target="_blank" for outgoing link and pdf files
View script.js
(function($) {
jQuery( document ).ready(function($) {
// external links to new window
add_target_blank_to_external_links();
// force PDF Files to open in new window
add_target_blank_to_pdf_links();
});
@thierrypigot
thierrypigot / functions.php
Created Dec 1, 2021
Check if a page is using a Beaver Builder layout
View functions.php
<?php
function is_beaver_builder_layout() {
if( class_exists( 'FLBuilderModel' ) && FLBuilderModel::is_builder_enabled() ) {
return true;
} else {
return false;
}
}
@thierrypigot
thierrypigot / search.php
Created Nov 12, 2021
WordPress search post type by post type. (Beaver Builder template file in this exemple)
View search.php
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden.
}
?>
<?php get_header(); ?>
<div class="fl-archive <?php FLLayout::container_class(); ?>">
<div class="<?php FLLayout::row_class(); ?>">
@thierrypigot
thierrypigot / waw-create-admin-user.php
Created Oct 19, 2021
Add a WordPress Admin User to the Database via PHP
View waw-create-admin-user.php
<?php
add_action( 'init', function () {
$username = 'wearewp';
$password = 'password';
$email_address = 'contact@wearewp.pro';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
@thierrypigot
thierrypigot / wp-endpoint-get-sites.php
Created Sep 17, 2021
WordPress Rest API - Ajout endpoint liste de tous les sites d'un multisites
View wp-endpoint-get-sites.php
<?php
function wearewp_api_custom_route_get_sites() {
$args = array(
'public' => 1, // I only want the sites marked Public
'archived' => 0,
'mature' => 0,
'spam' => 0,
'deleted' => 0,
);
@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);
}