如何通过Wordpress帖子上的快捷码添加小部件
我们有没有办法给已经创建的小部件分配一个短代码,以后再使用 在我们特定的帖子和页面中使用快捷代码来显示小部件,而不是简单的方法如何通过Wordpress帖子上的快捷码添加小部件,wordpress,Wordpress,我们有没有办法给已经创建的小部件分配一个短代码,以后再使用 在我们特定的帖子和页面中使用快捷代码来显示小部件,而不是简单的方法 在边栏中显示小部件?我在谷歌上搜索了一下,没有找到任何相关信息。我还没有完全理解你的问题。但据我所知,以下解决方案可能对您有所帮助: 这是在页面/帖子上调用小部件的插件: 试试上面提到的插件。这可能对你有帮助 希望对你有帮助 将此函数添加到主题的functions.php中 function widget($atts) { global $wp_widget_
在边栏中显示小部件?我在谷歌上搜索了一下,没有找到任何相关信息。我还没有完全理解你的问题。但据我所知,以下解决方案可能对您有所帮助: 这是在页面/帖子上调用小部件的插件: 试试上面提到的插件。这可能对你有帮助
希望对你有帮助 将此函数添加到主题的functions.php中
function widget($atts) {
global $wp_widget_factory;
extract(shortcode_atts(array(
'widget_name' => FALSE
), $atts));
$widget_name = wp_specialchars($widget_name);
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;
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('widget','widget');
[widget widget_name="Your_Custom_Widget"]