Følg disse trin for at tilføje tilpassede stil-widgets til dit WordPress-websted:
Trin 1:Opret en brugerdefineret widget-klasse
1. Åbn dit temas functions.php-fil.
2. Tilføj følgende kode for at oprette en ny widgetklasse:
``` php
klasse Custom_Styles_Widget udvider WP_Widget {
offentlig funktion __construct() {
$widget_ops =array(
'classname' => 'custom-styles-widget',
'description' => 'Viser brugerdefinerede stilarter.',
);
parent::__construct( 'custom-styles-widget', 'Custom Styles Widget', $widget_ops );
}
public function widget( $args, $instance ) {
// Vis widgetten.
ekko '
'. $instance['custom_styles'] . '
';
}
public function form( $instance ) {
// Vis widgetformularen.
$custom_styles =( isset( $instance['custom_styles']) ) ? esc_attr( $instance['custom_styles'] ) :'';
ekko'