wordpress技巧

一般博客的小工具栏都在两侧或者底部位置,有没有想过在你的文章中也能添加一个小工具的位置。你当然可以安装一个创建短代码的插件,或者你也可以使用代码来完成同样的功能。

把下面的代码添加到您的functions.php文件中。


register_sidebar( array(
'id' => 'wpsites-widget',
'name' => __( 'Custom Widget', 'wpsites' ),
'description' => __( 'Custom Widget Area', 'wpsites' ),
'before_widget' => '<div>',
'after_widget' => '</div>',
) );

add_shortcode( 'wpsites_widget', 'wpsites_shortcode_widget_area' );
/**
* @author Brad Dalton
* @example http://wpsites.net/
* @copyright 2014 WP Sites
*/
function wpsites_shortcode_widget_area() {
ob_start();
dynamic_sidebar( 'wpsites-widget', array(
'before' => '<div class="wpsites-widget widget-area">',
'after' => '</div>',
) );
$wpsiteswidget = ob_get_contents();
ob_end_clean();
return $wpsiteswidget;

}

然后,在您需要小工具的位置插入短代码[wpsites_widget]

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注