Skip to content

Instantly share code, notes, and snippets.

View thierrypigot's full-sized avatar

Thierry Pigot thierrypigot

View GitHub Profile
@thierrypigot
thierrypigot / shortcode.php
Created December 19, 2022 14:44
Shortcode 2
<?php
function my_custom_shortcode($params) {
echo 'Hello World! You specified the following parameters: ' . $params['param1'] . ' and ' . $params['param2'];
}
add_shortcode('hello_world', 'my_custom_shortcode');
?>
@thierrypigot
thierrypigot / shortcode.php
Created December 19, 2022 14:43
Shortcode 1
<?php
function my_custom_shortcode() {
echo 'Hello World!';
}
add_shortcode('hello_world', 'my_custom_shortcode');
?>
<?php
class Mon_Widget extends WP_Widget {
// Définit le constructeur
function __construct() {
$widget_ops = array(
'classname' => 'mon_widget',
'description' => 'Affiche le titre du site Web.'
);
parent::__construct( 'mon_widget', 'Mon Widget', $widget_ops );
@thierrypigot
thierrypigot / functions.php
Created October 7, 2022 13:49
WooCommerce - Add a surcharge based on the delivery country (exclude France)
<?php
/**
* Add a 1% surcharge to your cart / checkout based on delivery country
* Taxes, shipping costs and order subtotal are all included in the surcharge amount
*/
add_action( 'woocommerce_cart_calculate_fees',' woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
@thierrypigot
thierrypigot / mu-blog-settings.php
Last active June 2, 2022 08:54
Add blog meta on WordPress multisite
<?php
class WeAreWP_Add_Blog_Order {
public static function init() {
$class = __CLASS__ ;
if ( empty( $GLOBALS[ $class ] ) )
$GLOBALS[ $class ] = new $class;
}
public function __construct() {
add_filter( 'wpmu_blogs_columns', array( $this, 'get_id' ) );
add_action( 'manage_sites_custom_column', array( $this, 'add_columns' ), 10, 2 );
@thierrypigot
thierrypigot / check-broken-link.php
Created April 25, 2022 14:22
Check for broken link with PHP
@thierrypigot
thierrypigot / functions.php
Created March 1, 2022 10:10
Date shortcode
<?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 January 21, 2022 15:02
jQuery add target="_blank" for outgoing link and pdf files
(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 December 1, 2021 09:32
Check if a page is using a Beaver Builder layout
<?php
function is_beaver_builder_layout() {
if( class_exists( 'FLBuilderModel' ) && FLBuilderModel::is_builder_enabled() ) {
return true;
} else {
return false;
}
}
@thierrypigot
thierrypigot / search.php
Created November 12, 2021 16:27
WordPress search post type by post type. (Beaver Builder template file in this exemple)
<?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(); ?>">