将变量传递到寄存器侧栏


Pass Variable to Register Sidebar?

我试图将包含图像url的变量传递到一个数组中,以便在我的WordPress主题中使用。

我希望它是动态的,所以我把html存储在一个变量中,但是我不明白为什么我不能把它传递到我的$args数组中。

这可能吗?

// Build a path to image
$path_start = '<img src="';
$site = get_bloginfo('template_directory');
$path_end = '/img/hr.png" class="hr">';
// Join it together
$full = $path_start . $site . $path_end;
// Pass it into Sidebar
function custom_sidebars() {
$args = array(
'id'            => 'applause-1',
'name'          => 'Applause 1',
'description'   => 'Main sidebar, above a horizontal rule',
'before_widget' => '',
'after_widget'  => $full,
'before_title'  => '',
'after_title'   => ''
);
etc.

在前面的例子中,我在函数的作用域之外定义了变量。

固定代码:

function custom_sidebars() {
// Build a path to image
$path_start = '<img src="';
$site = get_bloginfo('template_directory');
$path_end = '/img/hr.png" class="hr">';
// Join it together
$full = $path_start . $site . $path_end;
$args = array(
'id'            => 'applause-1',
'name'          => 'Applause 1',
'description'   => 'Main sidebar, above a horizontal rule',
'before_widget' => '',
'after_widget'  => $full,
'before_title'  => '',
'after_title'   => ''
);