Skip to content

Instantly share code, notes, and snippets.

@PauliusKrutkis
Last active March 7, 2017 20:30
Show Gist options
  • Save PauliusKrutkis/a6e43de06a8404bcfb834a95fbf225d2 to your computer and use it in GitHub Desktop.
Save PauliusKrutkis/a6e43de06a8404bcfb834a95fbf225d2 to your computer and use it in GitHub Desktop.
Wordpress widget with acf snippet
<?php
function registerThemeWidgets()
{
register_widget('Example_widget');
}
add_action('widgets_init', 'registerThemeWidgets');
class Example_widget extends WP_Widget
{
function __construct()
{
parent::__construct(
'example_widget',
'Example'
);
}
public function widget($args, $instance)
{
echo $args['before_widget'];
echo $args['after_widget'];
}
public function form($instance)
{
}
}
function exampleWidgetParams($params)
{
$widgetName = $params[0]['widget_name'];
$widgetId = $params[0]['widget_id'];
if ($widgetName != 'Example') {
return $params;
}
$content = get_field('content', 'widget_' . $widgetId);
if ($content) {
$params[0]['before_widget'] .= $content;
}
return $params;
}
add_filter('dynamic_sidebar_params', 'exampleWidgetParams');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment