Skip to content

Instantly share code, notes, and snippets.

@thierrypigot
Created December 19, 2022 14:42
Show Gist options
  • Save thierrypigot/84926120ba3a084f52251fd35d454fbf to your computer and use it in GitHub Desktop.
Save thierrypigot/84926120ba3a084f52251fd35d454fbf to your computer and use it in GitHub Desktop.
<?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 );
}
// Définit le contenu du widget
public function widget( $args, $instance ) {
// Définit le contenu à afficher
echo $args['before_widget'];
echo '<h2>'.get_bloginfo( 'name' ).'</h2>';
echo $args['after_widget'];
}
// Définit les options du widget
public function form( $instance ) {
// Pas de paramètres
}
}
// Enregistre le widget
function register_mon_widget() {
register_widget( 'Mon_Widget' );
}
add_action( 'widgets_init', 'register_mon_widget' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment