【发布时间】:2018-04-09 20:00:51
【问题描述】:
我已经编写了一个代码,以便您可以轻松地向网站添加样式表,这是用于我们的框架的。
它有效,但如果我使用它,CSS 是否也会更改仪表板布局?与定制器相同,如果我不使用此方法,但只是一个普通的 wp enqueue 它可以工作,但这不是我想要的。
class theme_setup{
function main_css_setup($css) {
wp_enqueue_style( 'style', get_template_directory_uri().'/css/'.$css.'.css' );
}
function add_css_main($css){
add_action( 'wp_enqueue_scripts', array($this, 'main_css_setup'),10,1 );
do_action( 'wp_enqueue_scripts', $css );
}
}
$theme_setup = new theme_setup();
$theme_setup->add_css_main('main');
仪表板更改: First example Second example
我认为这与do_action 有关,我搜索了我的最佳行为,但没有任何运气。
我正在使用“do_action”传递用户使用add_css_main 提供的参数,我知道我可以使用全局变量,但这些是“静态的”,这将使这个想法消失灵活的功能。
更新:
function themename_custom_logo_setup($height,$width) {
$defaults = array(
'height' => $height,
'width' => $width,
'flex-height' => true,
'flex-width' => true,
'header-text' => array( 'site-title', 'site-description' ),
);
add_theme_support( 'custom-logo', $defaults );
}
function add_custom_logo($width,$height){
add_action( 'after_setup_theme', array($this, 'themename_custom_logo_setup' ),10,2);
do_action( 'after_setup_theme', $height,$width);
}
$theme_setup->add_custom_logo(88,250);
确实有效,但变量根本没有传递。
【问题讨论】:
-
你为什么使用
do_action? -
@SamvelAleqsanyan 要传递参数,找不到任何其他可行的方法,期望..创建一个全局变量,但函数的意义就消失了。
-
使用你的类属性传递参数
-
正如我所说,我不想使用变量或全局变量,因为这会带走“灵活”部分。
-
@SamvelAleqsanyan 看到你的答案,是的,它可以工作 2,但是.. 如果我使用 add_css_main 不止一次,只有最后一个工作..
标签: php wordpress class wordpress-theming