Skip to content

Instantly share code, notes, and snippets.

View thierrypigot's full-sized avatar

Thierry Pigot thierrypigot

View GitHub Profile
<?php
// Déclaration de la fonction pour créer le Custom Post Type
function ma_fonction_cpt() {
// Définition des labels pour le CPT
$labels = array(
'name' => _x( 'Produits', 'Post Type General Name', 'mon_text_domain' ),
'singular_name' => _x( 'Produit', 'Post Type Singular Name', 'mon_text_domain' ),
'menu_name' => __( 'Produits', 'mon_text_domain' ),
'parent_item_colon' => __( 'Produit parent:', 'mon_text_domain' ),
<?php
// Create a new "Heures d'ouverture" taxonomy
function create_opening_hours_taxonomy() {
$labels = array(
'name' => _x( 'Heures d'ouverture', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Heure d'ouverture', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Rechercher des heures d'ouverture', 'textdomain' ),
'all_items' => __( 'Toutes les heures d'ouverture', 'textdomain' ),
'parent_item' => __( 'Heure d'ouverture parente', 'textdomain' ),
@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();
});