{"id":4711,"date":"2025-10-20T09:16:22","date_gmt":"2025-10-20T01:16:22","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4711.html"},"modified":"2025-11-07T10:01:57","modified_gmt":"2025-11-07T02:01:57","slug":"wordpress%e8%8e%b7%e5%8f%96%e5%b9%b6%e6%89%93%e5%8d%b0%e7%bd%91%e7%ab%99logo%e7%9a%84%e5%bc%80%e5%8f%91%e4%bb%a3%e7%a0%81","status":"publish","type":"bjjc","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4711.html","title":{"rendered":"wordpress\u524d\u540e\u53f0logo\u7684\u83b7\u53d6\u548c\u4fee\u6539\u7684\u4ee3\u7801"},"content":{"rendered":"<p>\u5728WordPress\u4e2d\u83b7\u53d6\u5e76\u6253\u5370\u7f51\u7ad9Logo\uff0c\u4e3b\u8981\u6709\u4e24\u79cd\u4e3b\u6d41\u65b9\u6cd5\uff1a\u4e00\u662f\u4f7f\u7528WordPress\u5185\u7f6e\u7684<strong>\u81ea\u5b9a\u4e49Logo\u529f\u80fd<\/strong>\uff0c\u8fd9\u662f\u6700\u63a8\u8350\u7684\u505a\u6cd5\uff1b\u4e8c\u662f\u6839\u636e\u9700\u8981<strong>\u5b9a\u5236\u767b\u5f55\u9875\u9762\u7684Logo<\/strong>\u3002<\/p><p>\u4e0b\u9762\u8fd9\u4e2a\u8868\u683c\u6c47\u603b\u4e86\u8fd9\u4e9b\u65b9\u6cd5\u7684\u6838\u5fc3\u4fe1\u606f\uff1a<\/p><figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u65b9\u6cd5\u7c7b\u522b<\/th><th>\u529f\u80fd\u8bf4\u660e<\/th><th>\u6838\u5fc3\u51fd\u6570\/\u94a9\u5b50<\/th><th>\u4e3b\u8981\u9002\u7528\u573a\u666f<\/th><\/tr><\/thead><tbody><tr><td><strong>\ud83d\ude80 \u81ea\u5b9a\u4e49Logo<\/strong><\/td><td>\u4e3a\u4e3b\u9898\u542f\u7528Logo\u652f\u6301\uff0c\u5e76\u5728\u524d\u53f0\u8c03\u7528<\/td><td><code>add_theme_support('custom-logo')<\/code>, <code>the_custom_logo()<\/code><\/td><td>\u7f51\u7ad9\u524d\u53f0\u9875\u7709\u3001\u9875\u811a\u7b49\u4f4d\u7f6e\u663e\u793aLogo<\/td><\/tr><tr><td><strong>\ud83d\udd11 \u767b\u5f55\u9875Logo<\/strong><\/td><td>\u5b9a\u5236WordPress\u9ed8\u8ba4\u767b\u5f55\u9875\u9762\u7684Logo\u6837\u5f0f\u548c\u94fe\u63a5<\/td><td><code>login_head<\/code>, <code>login_headerurl<\/code>, <code>login_headertitle<\/code><\/td><td>\u66ff\u6362wp-login.php\u9875\u9762\u7684Logo<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">\u4f7f\u7528\u81ea\u5b9a\u4e49Logo\u529f\u80fd<\/h2><p>\u8fd9\u662f\u5728\u73b0\u4ee3WordPress\u4e3b\u9898\u4e2d\u6dfb\u52a0Logo\u7684\u6807\u51c6\u505a\u6cd5\uff0c\u5141\u8bb8\u7528\u6237\u901a\u8fc7\u540e\u53f0\u53ef\u89c6\u5316\u5730\u66f4\u6362Logo\u3002<\/p><h3 class=\"wp-block-heading\">1. \u4e3a\u4e3b\u9898\u542f\u7528Logo\u652f\u6301<\/h3><p>\u5c06\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5230\u5f53\u524d\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u4e2d\uff1a<\/p><pre class=\"wp-block-code\"><code>\/\/ \u4e3a\u4e3b\u9898\u542f\u7528\u81ea\u5b9a\u4e49Logo\u529f\u80fd\nfunction themename_custom_logo_setup() {\n    $defaults = array(\n        'height'      =&gt; 100, \/\/ \u9ed8\u8ba4\u9ad8\u5ea6\n        'width'       =&gt; 400, \/\/ \u9ed8\u8ba4\u5bbd\u5ea6\n        'flex-height' =&gt; true, \/\/ \u5141\u8bb8\u7075\u6d3b\u9ad8\u5ea6\n        'flex-width'  =&gt; true, \/\/ \u5141\u8bb8\u7075\u6d3b\u5bbd\u5ea6\n        'header-text' =&gt; array('site-title', 'site-description'), \/\/ \u9690\u85cf\u5728Logo\u540e\u7684\u7ad9\u70b9\u6807\u9898\u548c\u63cf\u8ff0\n    );\n    add_theme_support('custom-logo', $defaults);\n}\nadd_action('after_setup_theme', 'themename_custom_logo_setup');<\/code><\/pre><p><em>\u53c2\u6570\u8bf4\u660e<\/em>\uff1a<code>height<\/code> \u548c <code>width<\/code> \u8bbe\u7f6eLogo\u7684\u663e\u793a\u5c3a\u5bf8\uff0c\u800c <code>flex-height<\/code> \u548c <code>flex-width<\/code> \u8bbe\u7f6e\u4e3a <code>true<\/code> \u65f6\uff0cLogo\u4f1a\u6839\u636e\u5b9e\u9645\u5c3a\u5bf8\u81ea\u9002\u5e94\uff0c\u5ffd\u7565\u56fa\u5b9a\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u8bbe\u7f6e\u3002<\/p><h3 class=\"wp-block-heading\">2. \u5728\u524d\u53f0\u6a21\u677f\u4e2d\u8c03\u7528Logo<\/h3><p>\u5728\u9700\u8981\u663e\u793aLogo\u7684\u6a21\u677f\u6587\u4ef6\uff08\u4f8b\u5982 <code>header.php<\/code>\uff09\u4e2d\uff0c\u653e\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p><pre class=\"wp-block-code\"><code>&lt;?php\n    \/\/ \u5728\u6a21\u677f\u4e2d\u6253\u5370Logo\n    if (has_custom_logo()) {\n        the_custom_logo();\n    } else {\n        echo '&lt;a href=\"' . home_url('\/') . '\"&gt;' . get_bloginfo('name') . '&lt;\/a&gt;';\n    }\n?&gt;<\/code><\/pre><p>\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u5148\u68c0\u67e5\u662f\u5426\u8bbe\u7f6e\u4e86\u81ea\u5b9a\u4e49Logo\uff0c\u5982\u679c\u8bbe\u7f6e\u4e86\u5c31\u6253\u5370\u51fa\u6765\uff0c\u5426\u5219\u663e\u793a\u7ad9\u70b9\u540d\u79f0\u4f5c\u4e3a\u56de\u9000\u3002<\/p><p>\u5b8c\u6210\u4ee5\u4e0a\u6b65\u9aa4\u540e\uff0c\u7528\u6237\u5c31\u53ef\u4ee5\u5728WordPress\u540e\u53f0\u7684&#8221;<strong>\u5916\u89c2<\/strong>&#8221; -&gt; &#8220;<strong>\u81ea\u5b9a\u4e49<\/strong>&#8221; -&gt; &#8220;<strong>\u7ad9\u70b9\u6807\u8bc6<\/strong>&#8220;\u4e2d\u4e0a\u4f20\u548c\u66f4\u6362Logo\uff0c\u5e76\u5b9e\u65f6\u9884\u89c8\u6548\u679c\u3002<\/p><h2 class=\"wp-block-heading\">\u5b9a\u5236\u767b\u5f55\u9875\u9762Logo<\/h2><p>\u5982\u679c\u4f60\u60f3\u66ff\u6362WordPress\u9ed8\u8ba4\u767b\u5f55\u9875\u9762\u7684Logo\uff0c\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u5230\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u6765\u5b9e\u73b0\u3002<\/p><h3 class=\"wp-block-heading\">1. \u66ff\u6362\u767b\u5f55\u9875\u7684Logo\u56fe\u7247<\/h3><pre class=\"wp-block-code\"><code>\/\/ \u81ea\u5b9a\u4e49\u767b\u5f55\u9875\u9762\u7684LOGO\u56fe\u7247\nfunction my_custom_login_logo() {\n    $logo_url = get_theme_file_uri('\/images\/login_logo.png'); \/\/ \u66ff\u6362\u4e3a\u4f60\u7684Logo\u8def\u5f84\n    echo '&lt;style type=\"text\/css\"&gt;\n        .login h1 a {\n            background-image: url(' . $logo_url . ') !important;\n            background-size: contain;\n            background-repeat: no-repeat;\n            background-position: center;\n            width: 100%;\n            height: 80px; \/* \u6839\u636e\u4f60\u7684\u56fe\u7247\u8c03\u6574\u9ad8\u5ea6 *\/\n        }\n    &lt;\/style&gt;';\n}\nadd_action('login_head', 'my_custom_login_logo');<\/code><\/pre><h3 class=\"wp-block-heading\">2. \u4fee\u6539\u767b\u5f55\u9875Logo\u7684\u94fe\u63a5<\/h3><p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u767b\u5f55\u9875\u7684Logo\u4f1a\u94fe\u63a5\u5230WordPress\u5b98\u7f51\u3002\u4ee5\u4e0b\u4ee3\u7801\u53ef\u4ee5\u5c06\u5176\u6539\u4e3a\u4f60\u7684\u9996\u9875\u94fe\u63a5\uff1a<\/p><pre class=\"wp-block-code\"><code>\/\/ \u5c06\u767b\u5f55\u9875\u9762LOGO\u7684\u94fe\u63a5\u6539\u4e3a\u9996\u9875\u94fe\u63a5\nfunction custom_loginlogo_url($url) {\n    return home_url('\/'); \/\/ \u4fee\u6539\u4e3a\u6307\u5411\u7f51\u7ad9\u9996\u9875\n}\nadd_filter('login_headerurl', 'custom_loginlogo_url');<\/code><\/pre><h3 class=\"wp-block-heading\">3. \u4fee\u6539\u767b\u5f55\u9875Logo\u7684\u6807\u9898\u63d0\u793a\u6587\u672c<\/h3><pre class=\"wp-block-code\"><code>\/\/ \u5c06\u767b\u5f55\u9875\u9762LOGO\u7684\u63d0\u793a\u6587\u672c\u6539\u4e3a\u7f51\u7ad9\u540d\u79f0\nfunction custom_loginlogo_desc($title) {\n    return get_bloginfo('name'); \/\/ \u4fee\u6539\u63d0\u793a\u6587\u672c\u4e3a\u7f51\u7ad9\u540d\u79f0\n}\nadd_filter('login_headertitle', 'custom_loginlogo_desc');<\/code><\/pre><h2 class=\"wp-block-heading\">\u8865\u5145\uff1a\u901a\u8fc7\u7f16\u7a0b\u65b9\u5f0f\u8bbe\u7f6eLogo<\/h2><p>\u5728\u67d0\u4e9b\u7279\u6b8a\u60c5\u51b5\u4e0b\uff0c\u4f8b\u5982\u5728\u5f00\u53d1\u4e3b\u9898\u7684&#8221;\u4e00\u952e\u6f14\u793a\u6570\u636e\u5bfc\u5165&#8221;\u529f\u80fd\u65f6\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u901a\u8fc7\u4ee3\u7801\u81ea\u52a8\u8bbe\u7f6eLogo\u3002\u8fd9\u65f6\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528 <code>wp_upload_bits<\/code> \u548c <code>set_theme_mod<\/code> \u51fd\u6570\u3002<\/p><pre class=\"wp-block-code\"><code>\/\/ \u901a\u8fc7\u4ee3\u7801\u8bbe\u7f6eLogo (\u793a\u4f8b)\nfunction set_logo_programmatically($image_url) {\n    \/\/ \u6ce8\u610f\uff1a\u6b64\u5904\u9700\u8981\u5b9e\u73b0\u56fe\u7247\u4e0a\u4f20\u5e76\u83b7\u53d6\u9644\u4ef6ID\u7684\u903b\u8f91\n    \/\/ \u8fd9\u662f\u4e00\u4e2a\u7b80\u5316\u7684\u793a\u4f8b\uff0c\u5b9e\u9645\u5e94\u7528\u4e2d\u9700\u8981\u5904\u7406\u6587\u4ef6\u4e0a\u4f20\u548c\u9644\u4ef6\u521b\u5efa\n    $upload = wp_upload_bits(basename($image_url), null, file_get_contents($image_url));\n    if (empty($upload['error'])) {\n        $file_path = $upload['file'];\n        $file_type = wp_check_filetype($file_path, null);\n        $attachment = array(\n            'post_mime_type' =&gt; $file_type['type'],\n            'post_title =&gt; sanitize_file_name(basename($file_path)),\n            'post_content' =&gt; '',\n            'post_status' =&gt; 'inherit'\n        );\n        $attach_id = wp_insert_attachment($attachment, $file_path);\n        require_once(ABSPATH . 'wp-admin\/includes\/image.php');\n        $attach_data = wp_generate_attachment_metadata($attach_id, $file_path);\n        wp_update_attachment_metadata($attach_id, $attach_data);\n\n        \/\/ \u5c06\u9644\u4ef6ID\u8bbe\u7f6e\u4e3a\u7f51\u7ad9\u7684Logo\n        set_theme_mod('custom_logo', $attach_id);\n    }\n}<\/code><\/pre><p><em>\u6ce8\u610f<\/em>\uff1a\u8fd9\u662f\u4e00\u4e2a\u6982\u5ff5\u6027\u793a\u4f8b\uff0c\u5b9e\u9645\u4f7f\u7528\u65f6\u9700\u8981\u5b8c\u5584\u9519\u8bef\u5904\u7406\u548c\u5b89\u5168\u9a8c\u8bc1\u3002<\/p><h2 class=\"wp-block-heading\">\u6838\u5fc3\u65b9\u6cd5\u603b\u7ed3<\/h2><ul class=\"wp-block-list\">\n<li><strong>\u5bf9\u4e8e\u5e38\u89c4\u4e3b\u9898\u5f00\u53d1<\/strong>\uff1a\u4f18\u5148\u4f7f\u7528 <strong>\u81ea\u5b9a\u4e49Logo\u529f\u80fd<\/strong> (<code>add_theme_support('custom-logo')<\/code> \u548c <code>the_custom_logo()<\/code>)\uff0c\u8fd9\u662f\u6700\u6807\u51c6\u4e14\u5bf9\u7528\u6237\u6700\u53cb\u597d\u7684\u65b9\u5f0f\u3002<\/li>\n\n\n\n<li><strong>\u9700\u8981\u4e2a\u6027\u5316\u767b\u5f55\u9875\u9762<\/strong>\uff1a\u4f7f\u7528 <code>login_head<\/code>, <code>login_headerurl<\/code> \u548c <code>login_headertitle<\/code> \u94a9\u5b50\u6765\u5b9a\u5236\u3002<\/li>\n\n\n\n<li><strong>\u9700\u8981\u81ea\u52a8\u5316\u914d\u7f6e<\/strong>\uff1a\u5728\u9700\u8981\u7f16\u7a0b\u8bbe\u7f6eLogo\u7684\u573a\u666f\uff0c\u4f7f\u7528 <code>set_theme_mod('custom_logo', $attachment_id)<\/code> \u6765\u5b9e\u73b0\u3002<\/li>\n<\/ul><p>\u5e0c\u671b\u8fd9\u4e9b\u4ee3\u7801\u548c\u8bf4\u660e\u80fd\u5e2e\u52a9\u4f60\u987a\u5229\u5730\u5728WordPress\u4e3b\u9898\u4e2d\u96c6\u6210Logo\u3002\u5982\u679c\u4f60\u5728\u5b9e\u73b0\u8fc7\u7a0b\u4e2d\u9047\u5230\u4efb\u4f55\u95ee\u9898\uff0c\u6216\u8005\u9700\u8981\u4e86\u89e3\u66f4\u5177\u4f53\u7684\u7ec6\u8282\uff0c\u968f\u65f6\u53ef\u4ee5\u7ee7\u7eed\u63d0\u95ee\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u5728WordPress\u4e2d\u83b7\u53d6\u5e76\u6253\u5370\u7f51\u7ad9Logo\uff0c\u4e3b\u8981\u6709\u4e24\u79cd\u4e3b\u6d41\u65b9\u6cd5\uff1a\u4e00\u662f\u4f7f\u7528WordPress\u5185\u7f6e\u7684\u81ea\u5b9a\u4e49Logo\u529f\u80fd\uff0c\u8fd9\u662f\u6700\u63a8\u8350\u7684\u505a\u6cd5\uff1b\u4e8c\u662f\u6839\u636e\u9700\u8981\u5b9a\u5236\u767b\u5f55\u9875\u9762\u7684Logo\u3002 \u4e0b\u9762\u8fd9\u4e2a\u8868\u683c\u6c47\u603b\u4e86\u8fd9\u4e9b\u65b9\u6cd5\u7684\u6838\u5fc3\u4fe1\u606f\uff1a \u65b9\u6cd5\u7c7b\u522b \u529f\u80fd\u8bf4\u660e \u6838\u5fc3\u51fd\u6570\/\u94a9\u5b50 \u4e3b\u8981\u9002\u7528\u573a\u666f \ud83d\ude80 \u81ea\u5b9a\u4e49Logo \u4e3a\u4e3b\u9898\u542f\u7528Logo\u652f\u6301\uff0c\u5e76\u5728\u524d\u53f0\u8c03\u7528..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":true},"tags":[50,59],"bjjc2nav":[14],"tuisongtax":[],"class_list":["post-4711","bjjc","type-bjjc","status-publish","hentry","tag-xsbdtj","tag-pzjc","bjjc2nav-jdztkf"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"\u524d\u540e\u53f0logo\u7684\u83b7\u53d6\u548c\u4fee\u6539","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":"\u524d\u540e\u53f0logo\u7684\u83b7\u53d6\u548c\u4fee\u6539"}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc\/4711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/bjjc"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=4711"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=4711"},{"taxonomy":"bjjc2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc2nav?post=4711"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=4711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}