<?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>excerpt_more &#8211; 小豬日常</title>
	<atom:link href="https://piglife.tw/tag/excerptmore/feed/" rel="self" type="application/rss+xml" />
	<link>https://piglife.tw</link>
	<description>Hello World，一個紀錄生活與學習的地方</description>
	<lastBuildDate>Wed, 10 Dec 2025 10:23:14 +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>excerpt_more &#8211; 小豬日常</title>
	<link>https://piglife.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>自訂 WordPress 摘要結尾文字的簡易方法</title>
		<link>https://piglife.tw/technical-notes/wordpress-excerpt-more-customize/</link>
					<comments>https://piglife.tw/technical-notes/wordpress-excerpt-more-customize/#respond</comments>
		
		<dc:creator><![CDATA[小豬]]></dc:creator>
		<pubDate>Wed, 10 Dec 2025 10:23:14 +0000</pubDate>
				<category><![CDATA[技術筆記]]></category>
		<category><![CDATA[excerpt_more]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://piglife.tw/technical-notes/wordpress-excerpt-more-customize/</guid>

					<description><![CDATA[介紹如何使用 WordPress 的 excerpt_more 過濾器簡單自訂文章摘要結尾文字，提升...]]></description>
										<content:encoded><![CDATA[<h2 class="wp-block-heading">前言</h2>
<p>在 WordPress 主題開發或客製化時，常會需要調整文章摘要（excerpt）結尾的文字，預設為「[&#8230;]」的顯示可能不符合設計需求。這段 PHP 程式碼示範如何用最簡單的方式修改摘要結尾文字，適合有基本 WordPress 開發經驗的工程師或自學者。</p>
<h2 class="wp-block-heading">為什麼要修改摘要結尾文字</h2>
<p>WordPress 預設的摘要結尾通常是「[&#8230;]」，這是用來表示文章內容被截斷。若想讓網站風格更統一或更符合閱讀體驗，可以透過過濾器（filter）自訂這段文字。</p>
<h2 class="wp-block-heading">透過 add_filter 修改 excerpt_more</h2>
<p>關鍵在於 WordPress 提供的 <code>excerpt_more</code> 過濾器，可以攔截並改寫摘要結尾文字。以下是程式碼片段：</p>
<pre><code class="lang-php language-php php">add_filter(&#039;excerpt_more&#039;, function($more) {
    return &#039;&hellip;&#039;;
});</code></pre>
<p>這段程式碼使用匿名函式（Closure）直接回傳一個單一的省略符號「…」，取代預設的「[&#8230;]」。</p>
<h3 class="wp-block-heading">程式碼解析</h3>
<ul>
<li><code>add_filter</code> 是 WordPress 用來掛載過濾器的函式。</li>
<li><code>&#039;excerpt_more&#039;</code> 是過濾器名稱，專門用來修改摘要後綴。</li>
<li>匿名函式接收 <code>$more</code> 參數（原本的結尾文字），但這裡直接忽略它，回傳自訂字串。</li>
</ul>
<p>這種寫法簡潔且易於維護，尤其適合只想快速改變摘要結尾的情境。</p>
<h2 class="wp-block-heading">實務應用與延伸</h2>
<ul>
<li>可將回傳字串改成其他符號或文字，例如「繼續閱讀」搭配連結。</li>
<li>若需要更複雜的摘要控制，可結合 <code>excerpt_length</code> 過濾器調整摘要長度。</li>
<li>注意部分主題或外掛可能會覆寫此過濾器，需確認優先權設定。</li>
</ul>
<h2 class="wp-block-heading">常見問題</h2>
<ul>
<li>
<p><strong>為什麼修改後沒效果？</strong>
可能是主題直接使用自訂函式產生摘要，未使用 WordPress 預設的 <code>the_excerpt()</code> 函式。</p>
</li>
<li>
<p><strong>如何同時修改摘要長度？</strong>
可搭配 <code>excerpt_length</code> 過濾器一起使用。</p>
</li>
</ul>
<h2 class="wp-block-heading">完整程式碼</h2>
<pre><code class="lang-php language-php php">&lt;?php
add_filter(&#039;excerpt_more&#039;, function($more) {
    return &#039;&hellip;&#039;;
});</code></pre>]]></content:encoded>
					
					<wfw:commentRss>https://piglife.tw/technical-notes/wordpress-excerpt-more-customize/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
