【发布时间】:2014-02-03 19:32:22
【问题描述】:
我想根据简码参数给头部添加一个样式标签。我为样式编写了一个函数,并希望在简码函数中调用它的add_action。
但是,样式并没有添加到头部。如果我在函数之外调用 add_action ,它会成功运行。 请告诉我如何在 php 函数中调用语句“add_action”,以及如何向函数发送参数以调用 add_action。
这是我的代码:
function ag_appearance( $year ){
?>
<style type="text/css">
/*Some style here*/
</style>
<?php
}
add_action( 'wp_head', 'ag_appearance' ); /* this is working */
function dp_agenda( $atts, $content = null ){
extract( shortcode_atts( array(
'year' => '',
'day' => '',
'summit' => '',
'complexity' => '',
'certification' => '',
'event' => '',
'make' => ''
), $atts ) );
add_action( 'wp_head', 'ag_appearance' );
/* this is not working, while i want to call here by $year parameter */
}
【问题讨论】:
-
这实际上已经被问过了。你可以在这里找到它:wordpress.stackexchange.com/questions/46167/…
标签: wordpress