<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Logo自訂 &#8211; 小豬日常</title>
	<atom:link href="https://piglife.tw/tag/logo/feed/" rel="self" type="application/rss+xml" />
	<link>https://piglife.tw</link>
	<description>Hello World，一個紀錄生活與學習的地方</description>
	<lastBuildDate>Wed, 10 Dec 2025 10:23:35 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://piglife.tw/wp-content/uploads/2017/10/cropped-logo-1-32x32.png</url>
	<title>Logo自訂 &#8211; 小豬日常</title>
	<link>https://piglife.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>自訂 WordPress 登入頁面 Logo 與連結設定教學</title>
		<link>https://piglife.tw/technical-notes/wordpress-custom-login-logo/</link>
					<comments>https://piglife.tw/technical-notes/wordpress-custom-login-logo/#respond</comments>
		
		<dc:creator><![CDATA[小豬]]></dc:creator>
		<pubDate>Wed, 10 Dec 2025 10:23:35 +0000</pubDate>
				<category><![CDATA[技術筆記]]></category>
		<category><![CDATA[Logo自訂]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://piglife.tw/technical-notes/wordpress-custom-login-logo/</guid>

					<description><![CDATA[說明如何透過 WordPress 鉤子自訂登入頁面 Logo 圖片、連結與標題，提升品牌一致性與使用...]]></description>
										<content:encoded><![CDATA[<h2 class="wp-block-heading">前言</h2>
<p>WordPress 預設的登入頁面 Logo 通常是 WordPress 自身標誌，對於品牌一致性或客製化需求來說，常常需要替換成自家 Logo。這篇文章針對有基本 PHP 與 WordPress 鉤子（Hook）概念的工程師，說明如何透過簡單的程式碼修改登入頁面 Logo 及其連結與標題。</p>
<h2 class="wp-block-heading">修改登入頁面 Logo 的方法</h2>
<p>WordPress 提供了 <code>login_enqueue_scripts</code> 動作鉤子，可以在登入頁面載入自訂 CSS。利用這個鉤子，我們可以注入 CSS 來改變 Logo 背景圖。</p>
<h3 class="wp-block-heading">主要程式碼片段</h3>
<pre><code class="lang-php language-php php">function ks_custom_login_logo() { ?&gt;
    &lt;style type=&quot;text/css&quot;&gt;
        body.login div#login h1 a {
            background-image: url(&#039;/wp-content/uploads/login-logo.svg&#039;);
            width: 200px;        /* 依你的 SVG 比例調整 */
            height: 80px;        /* 依你的 SVG 比例調整 */
            background-size: contain;
            background-repeat: no-repeat;
            background-position: center;
            padding-bottom: 0;
        }
    &lt;/style&gt;
&lt;?php }
add_action( &#039;login_enqueue_scripts&#039;, &#039;ks_custom_login_logo&#039; );</code></pre>
<p>這段程式碼將登入頁面中 Logo 的背景圖片改為指定路徑的 SVG，並調整尺寸與顯示方式，確保圖片完整且置中。</p>
<h2 class="wp-block-heading">自訂 Logo 點擊連結與標題</h2>
<p>預設 WordPress 登入頁 Logo 點擊會導向 wordpress.org，且滑鼠移到 Logo 上會顯示 &#8220;Powered by WordPress&#8221;。若想改為導向自己網站首頁，並顯示網站名稱，可以使用以下兩個過濾器：</p>
<pre><code class="lang-php language-php php">function ks_custom_login_logo_url( $url ) {
    return home_url( &#039;/&#039; );
}
add_filter( &#039;login_headerurl&#039;, &#039;ks_custom_login_logo_url&#039; );

function ks_custom_login_logo_title( $title ) {
    return get_bloginfo( &#039;name&#039; );
}
add_filter( &#039;login_headertext&#039;, &#039;ks_custom_login_logo_title&#039; );</code></pre>
<p>這樣使用者點擊 Logo 就會回到網站首頁，且滑鼠懸停時顯示網站名稱，提升品牌辨識度。</p>
<h2 class="wp-block-heading">實務應用與優化建議</h2>
<ul>
<li><strong>Logo 圖片路徑</strong>：請確保 <code>background-image</code> 的 URL 是正確且可存取的路徑，通常放在 WordPress 媒體庫或主題資料夾。</li>
<li><strong>尺寸調整</strong>：根據 Logo 圖檔比例調整 <code>width</code> 與 <code>height</code>，避免變形。</li>
<li><strong>響應式設計</strong>：可進一步用媒體查詢調整不同裝置的尺寸。</li>
<li><strong>安全性</strong>：避免在登入頁面加入過多外部資源，確保載入速度與安全。</li>
</ul>
<h2 class="wp-block-heading">常見問題與注意事項</h2>
<ul>
<li>若修改後 Logo 不顯示，請檢查圖片路徑是否正確，並清除瀏覽器快取。</li>
<li>使用 SVG 時，確保檔案安全且無惡意程式碼。</li>
<li>若有快取外掛或 CDN，請同步清除快取。</li>
</ul>
<h2 class="wp-block-heading">完整程式碼</h2>
<pre><code class="lang-php language-php php">&lt;?php
// 修改 WordPress 登入頁 Logo
function ks_custom_login_logo() { ?&gt;
    &lt;style type=&quot;text/css&quot;&gt;
        body.login div#login h1 a {
            background-image: url(&#039;/wp-content/uploads/login-logo.svg&#039;);
            width: 200px;        /* 依你的 SVG 比例調整 */
            height: 80px;        /* 依你的 SVG 比例調整 */
            background-size: contain;
            background-repeat: no-repeat;
            background-position: center;
            padding-bottom: 0;
        }
    &lt;/style&gt;
&lt;?php }
add_action( &#039;login_enqueue_scripts&#039;, &#039;ks_custom_login_logo&#039; );

// 自訂 Logo 點擊連結為首頁
function ks_custom_login_logo_url( $url ) {
    return home_url( &#039;/&#039; );
}
add_filter( &#039;login_headerurl&#039;, &#039;ks_custom_login_logo_url&#039; );

// 自訂 Logo 滑鼠懸停標題為網站名稱
function ks_custom_login_logo_title( $title ) {
    return get_bloginfo( &#039;name&#039; );
}
add_filter( &#039;login_headertext&#039;, &#039;ks_custom_login_logo_title&#039; );</code></pre>]]></content:encoded>
					
					<wfw:commentRss>https://piglife.tw/technical-notes/wordpress-custom-login-logo/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
