最近接到一个'历史悠久'项目,Magento2 整合Wordpress。客户基本上都是在Wordpress操作前端的界面。
项目的基本条件:
- Magento 2。3
- 已安装Fishpig
- Wordpress一切配置完成,运行正常
我接到的第一个任务是,修改 Wordpress default button style, 包括前端style和Wordpress后端界面的style。
前端style其实不难,只需要以Magento的模式,在前端theme中,创建一个less文件即可。
但是在后端,我发现Fishpig做到了Wordpress前后端分离,也就是当用户在Wordpress后端界面,并不会运行任何Magento前端的文件。所以,我们需要单独创建后端Wordpress theme,或者在已安装的theme中进行更改。
在我的项目中,Wordpress已经安装Fishpig Wordpress theme, 所以我的做法是,在wordpress/wp-content/themems/fishpig/css/添加新的CSS文件 wp-admin.css.
添加local.php在 wordpress/wp-content/themes/fishpig中,此为官方声明的做法。
// create local.php
// wordpress/wp-content/themes/fishpig/local.php
<?php
function adminStyleCss() {
$url = get_option('siteurl');
$url = $url . '/wp-content/themes/my-theme/styles/wp-admin.css';
echo '<!-- custom admin css -->
<link rel="stylesheet" type="text/css" href="' . $url . '" />
<!-- /end custom adming css -->';
}
add_action('admin_head', 'adminStyleCss');
?>
添加成功后,wp-admin.css 仅在Wordpress后端页面中加载。