I am trying to use a function I found to call widgets on the wysiwyg editor on WordPress, however it doesn’t seem to be working.
the short code is:
[wysiwyg_widget id="sidebar"]
The function itself is:
function wysiwyg_widget( $atts ) {
global $wp_widget_factory;
extract( shortcode_atts( array(
'widget_name' => "WYSIWYG_Widgets_Widget",
'id' => null,
), $atts ) );
if ( ! is_a( $wp_widget_factory->widgets[ $widget_name ], 'WP_Widget' ) ) :
$wp_class = 'WP_Widget_' . ucwords( strtolower( $class ) );
if ( ! is_a ( $wp_widget_factory->widgets[ $wp_class ], 'WP_Widget' ) ) :
return '<p>' .sprintf( __( "%s: Widget class not found. Make sure this widget exists and the class name is correct" ), '<strong>' . $class . '</strong>' ) . '</p>';
else:
$class = $wp_class;
endif;
endif;
if ( ! is_null( $id ) ) {
$instance['wysiwyg-widget-id'] = $id;
}
ob_start();
the_widget( $widget_name, $instance, array(
'widget_id'=>'arbitrary-instance-'.$id,
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
) );
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode( 'wysiwyg_widget','wysiwyg_widget' );
Any suggestions or if there is another way to do it without a plugin? Thank you for helping in advance!