Skip to content

Instantly share code, notes, and snippets.

@ABooooo
Last active February 11, 2019 09:59
Show Gist options
  • Save ABooooo/3723ca9ed595aef34dab1c4240d6004c to your computer and use it in GitHub Desktop.
Save ABooooo/3723ca9ed595aef34dab1c4240d6004c to your computer and use it in GitHub Desktop.
// Register Sidebar
function alle_sprachen_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Header-Hero', 'alle_sprachen' ),
'id' => 'header_hero',
'description' => esc_html__( 'Add widgets here.', 'alle_sprachen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'alle_sprachen_widgets_init' );
// Register Widget
if(!class_exists('GeneralTextWidget')) {
class GeneralTextWidget extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'generaltext_widget',
'description' => 'Text widget Widget built with ACF Pro',
);
parent::__construct( 'generaltext_widget', 'Text Widget', $widget_ops );
}
public function widget( $args, $instance ) {
// get widget ID
$acf_widget_id = 'widget_' . $args['widget_id'];
// Add ACF Group Fields
$contentleft = get_field('general_textbox', $acf_widget_id);
echo '<p class="c-hero-block--content-left__titel">';
echo $contentleft['inhalt_links_titel'];
echo '</p><div class="c-hero-block--content-left__textblock">';
echo $contentleft['inhalt_links_text'];
echo '</div>';
}
public function form( $instance ) {
// outputs the options form on admin
}
public function update( $new_instance, $old_instance ) {
//return $new_instance; // that is not nececesarrily
}
}
}
/**
* Register Widgets
*/
function register_widgets()
{
register_widget( 'GeneralTextWidget' );
}
add_action( 'widgets_init', 'register_widgets' );
// Add widget to sidebar and call sidebar in DOM
<?php dynamic_sidebar( 'header_hero' ); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment