浏览文章

文章信息

Magento2修改后台登陆logo-主题模块方式|How to change default Magento 2 Admin Logo by module 19706

按照步骤:

  1. app/code/ [VENDORNAME] / [模块名] /registration.php
<?php \Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    '[VendorName]_[ModuleName]',
    __DIR__);
?>
  1. app/code/ [VENDORNAME] / [模块名] /etc/module.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="[VendorName]_[ModuleName]" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Theme"/>
        </sequence>
    </module>
</config>
  1. app/code/ [VENDORNAME] / [模块名] /etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Theme\Model\View\Design">
        <arguments>
            <argument name="themes" xsi:type="array">
                <item name="adminhtml" xsi:type="string">[VendorName]/[themename]</item>
            </argument>
        </arguments>
    </type>
</config>
  1. app/code/ adminhtml / [VENDORNAME] / [THEMENAME] /registration.php
<?php \Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
    'adminhtml/[VendorName]/[themename]',
    __DIR__);
?>
  1. app/code/ adminhtml / [VENDORNAME] / [THEMENAME] /theme.xml
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>Theme Title</title>
    <parent>Magento/backend</parent>
</theme>
  1. app/code/ adminhtml / [VENDORNAME] / [THEMENAME] /Magento_Backend/layout/admin_login.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-login" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="styles" />
    <body>
        <referenceBlock name="logo">
            <arguments>
                <argument name="logo_image_src" xsi:type="string">images/login-logo.svg</argument>
            </arguments>
        </referenceBlock>
    </body>
 </page>
  1. app/code/ adminhtml / [VENDORNAME] / [THEMENAME] /web/images/login-logo.svg
  2. app/code/ adminhtml / [VENDORNAME] / [THEMENAME] /Magento_Backend/layout/default.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="header">
            <referenceBlock name="logo">
                <arguments>
                    <argument name="logo_img_width" xsi:type="number">300</argument> 
                    <argument name="logo_img_height" xsi:type="number">300</argument>
                    <argument name="show_part" xsi:type="string">logo</argument>
                    <argument name="edition" translate="true" xsi:type="string">Community Edition</argument>
                    <argument name="logo_image_src" xsi:type="string">images/menu-logo.svg</argument>
                </arguments>
            </referenceBlock>
        </referenceContainer>
    </body>
</page>
  1. app/code/ adminhtml / [VENDORNAME] / [THEMENAME] /web/images/menu-logo.svg
  2. Magento CLI
php bin/magento setup:upgrade
php bin/magento setup:di:compile

注意:

  1. 对于管理员登录页面徽标更改,请按照步骤6和7进行操作
  2. 对于管理员菜单徽标更改,请按照步骤 - 8和9进行操作

注意:可以 随意使用PNG文件而不是SVG作为徽标。

注意: 如果管理页面上未反映更改,尝试以下步骤:

  1. 卸载手动添加的主题

    • mysql -u <user> -p -e "delete from <dbname>.theme where theme_path ='<VendorName>/<themename>' AND area ='adminhtml' limit 1"
  2. 升级Magento应用程序,数据库数据和架构

    • php bin/magento setup:upgrade
    • php bin/magento setup:di:compile - (Optional)
    • php bin/magento setup:static-content:deploy -f
    • php bin/magento c:c && php bin/magento c:f


原创