Last active
March 7, 2017 20:30
-
-
Save PauliusKrutkis/a6e43de06a8404bcfb834a95fbf225d2 to your computer and use it in GitHub Desktop.
Wordpress widget with acf snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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