如何创建自己的基本WordPress小部件

时间:2016-10-01 09:42:27

标签: javascript php jquery html wordpress

我是wordpress的初学者,我找到了许多用于创建小部件的插件,但我想创建一个自定义文本和RSS小部件,就像每个WordPress安装附带的小部件一样。它允许用户向WordPress网站添加文本,视频,图像,自定义列表等。我应该怎么做。

1 个答案:

答案 0 :(得分:1)

//Put This code in themes -> function.php
register_sidebar( array(
    'id'          => 'custom-widget',
    'name'        => __( 'Custom Widget', $text_domain ),
    'description' => __( 'This is custom widget.', $text_domain ),
));

//After place code to function.php you can see your widget in your dashboard widget.

//Place This code where you display your widget
if (function_exists( 'dynamic_sidebar' ) && 
    dynamic_sidebar( sprintf( 'custom-widget', $i ) )
)