<?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>admin_head &#8211; 小豬日常</title>
	<atom:link href="https://piglife.tw/tag/admin_head/feed/" rel="self" type="application/rss+xml" />
	<link>https://piglife.tw</link>
	<description>Hello World，一個紀錄生活與學習的地方</description>
	<lastBuildDate>Fri, 12 Dec 2025 14:51:51 +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>admin_head &#8211; 小豬日常</title>
	<link>https://piglife.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>WooCommerce 會員後台嵌入 Amelia 預約日曆與隱藏管理員選單實作筆記</title>
		<link>https://piglife.tw/technical-notes/woocommerce-amelia-calendar-iframe/</link>
					<comments>https://piglife.tw/technical-notes/woocommerce-amelia-calendar-iframe/#respond</comments>
		
		<dc:creator><![CDATA[小豬]]></dc:creator>
		<pubDate>Thu, 06 Feb 2025 10:39:41 +0000</pubDate>
				<category><![CDATA[技術筆記]]></category>
		<category><![CDATA[admin_head]]></category>
		<category><![CDATA[amelia]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[woocommerce]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[會員後台]]></category>
		<category><![CDATA[選單擴充]]></category>
		<guid isPermaLink="false">https://piglife.tw/?p=484</guid>

					<description><![CDATA[介紹如何在 WooCommerce 會員後台新增 Amelia 預約日曆選單，並利用 admin_h...]]></description>
										<content:encoded><![CDATA[<h2 class="wp-block-heading">前言</h2>
<p>在 WooCommerce 會員後台嵌入 Amelia 預約日曆，可以讓用戶直接查看與管理預約，提升使用體驗。但直接嵌入 WordPress 後台頁面時，會看到不必要的管理員選單與工具列，影響介面整潔度。本文將介紹如何利用 WordPress 的 <code>admin_head</code> 鉤子與 WooCommerce 的會員選單過濾器，達成隱藏管理員元素並新增「我的日曆」選單的功能。</p>
<h2 class="wp-block-heading">隱藏 WordPress 管理員選單與工具列</h2>
<p>當 iframe 載入 WordPress 後台 Amelia 預約頁面時，左側選單、頂部工具列等管理員元素會干擾介面。透過 <code>admin_head</code> 鉤子判斷 URL 是否帶有 <code>iframe=true</code> 參數，動態插入 CSS 隱藏這些元素，並調整內容區域寬度與頁面邊距。</p>
<p>關鍵程式碼片段：</p>
<pre><code class="lang-php language-php php">function hide_admin_elements_for_iframe() {
 if (isset($_GET[&#039;iframe&#039;]) &amp;&amp; $_GET[&#039;iframe&#039;] == &#039;true&#039;) {
  echo &#039;
&lt;style&gt;
   #adminmenumain, #wpadminbar, .update-nag, #screen-meta, #screen-options-link-wrap, #contextual-help-link-wrap {
    display: none !important;
   }
   #wpcontent, #wpfooter { margin-left: 0; }
   html.wp-toolbar { padding-top: 0 !important; }
   body { margin: 0; padding: 0; }
   #wpfooter { display: none !important; }
  &lt;/style&gt;&#039;;
 }
}
add_action(&#039;admin_head&#039;, &#039;hide_admin_elements_for_iframe&#039;);</code></pre>
<p>這段程式碼確保只有在 iframe 模式下才隱藏管理員介面元素，避免影響正常管理操作。</p>
<h2 class="wp-block-heading">在 WooCommerce 會員後台新增「我的日曆」選單</h2>
<p>為方便用戶直接在會員中心查看 Amelia 預約日曆，使用 <code>add_rewrite_endpoint</code> 註冊新端點 <code>ameliacustomercalendar</code>，並透過 <code>woocommerce_account_menu_items</code> 過濾器在「我的課程」後新增「我的日曆」選單。</p>
<p>點擊「我的日曆」時，利用 <code>woocommerce_account_ameliacustomercalendar_endpoint</code> 鉤子輸出 iframe，載入 Amelia 預約日曆頁面，並帶入 <code>iframe=true</code> 參數以隱藏管理員元素。</p>
<p>關鍵程式碼片段：</p>
<pre><code class="lang-php language-php php">function add_ameliacustomercalendar_to_myaccount_menu() {
 add_rewrite_endpoint(&#039;ameliacustomercalendar&#039;, EP_ROOT | EP_PAGES);

 add_filter(&#039;woocommerce_account_menu_items&#039;, function($menu_links) {
  $new_menu_links = [];
  foreach ($menu_links as $key =&gt; $label) {
   $new_menu_links[$key] = $label;
   if ($key === &#039;ameliacustomerpanel&#039;) {
    $new_menu_links[&#039;ameliacustomercalendar&#039;] = &#039;我的日曆&#039;;
   }
  }
  return $new_menu_links;
 });

 add_action(&#039;woocommerce_account_ameliacustomercalendar_endpoint&#039;, function() {
  echo &#039;&lt;iframe width=&quot;100%&quot; height=&quot;600&quot; src=&quot;/wp-admin/admin.php?page=wpamelia-calendar&amp;iframe=true&quot;&gt;&lt;/iframe&gt;&#039;;
 });
}
add_action(&#039;init&#039;, &#039;add_ameliacustomercalendar_to_myaccount_menu&#039;);</code></pre>
<h2 class="wp-block-heading">測試與驗證</h2>
<ol>
<li>在瀏覽器網址列加入 <code>?iframe=true</code>，確認 WordPress 管理員選單與工具列是否隱藏。</li>
<li>進入 WooCommerce 會員後台，確認「我的日曆」選單是否出現。</li>
<li>點擊「我的日曆」，檢查 iframe 是否正確載入 Amelia 預約日曆，且無多餘管理員元素。</li>
</ol>
<h2 class="wp-block-heading">延伸與常見坑</h2>
<ul>
<li>若使用快取插件，新增端點後可能需要刷新重寫規則（Permalinks）。</li>
<li>iframe 高度可依需求調整，避免出現滾動條。</li>
<li>確保 Amelia 預約系統權限設定允許會員查看。</li>
</ul>
<h2 class="wp-block-heading">完整程式碼</h2>
<pre><code class="lang-text language-text text">function hide_admin_elements_for_iframe() {
 if (isset($_GET[&#039;iframe&#039;]) &amp;&amp; $_GET[&#039;iframe&#039;] == &#039;true&#039;) {
  echo &#039;
&lt;style&gt;
   #adminmenumain, /* 左側選單 */
   #wpadminbar, /* 頂部管理工具列 */
   .update-nag, /* 更新通知 */
   #screen-meta, /* 屏幕選項 */
   #screen-options-link-wrap, /* 屏幕選項按鈕 */
   #contextual-help-link-wrap /* 說明按鈕 */
   {
    display: none !important;
   }
   #wpcontent, #wpfooter{
    margin-left: 0;
   }
   html.wp-toolbar {
    padding-top: 0 !important;
   }
   body {
    margin: 0;
    padding: 0;
   }
   #wpfooter{
    display: none !important;
   }
  &lt;/style&gt;&#039;;
 }
}
add_action(&#039;admin_head&#039;, &#039;hide_admin_elements_for_iframe&#039;);

function add_ameliacustomercalendar_to_myaccount_menu() {
 add_rewrite_endpoint(&#039;ameliacustomercalendar&#039;, EP_ROOT | EP_PAGES);

 add_filter(&#039;woocommerce_account_menu_items&#039;, function($menu_links) {
  $new_menu_links = [];
  foreach ($menu_links as $key =&gt; $label) {
   $new_menu_links[$key] = $label;
   if ($key === &#039;ameliacustomerpanel&#039;) {
    $new_menu_links[&#039;ameliacustomercalendar&#039;] = &#039;我的日曆&#039;;
   }
  }
  return $new_menu_links;
 });

 add_action(&#039;woocommerce_account_ameliacustomercalendar_endpoint&#039;, function() {
  echo &#039;&lt;iframe width=&quot;100%&quot; height=&quot;600&quot; src=&quot;/wp-admin/admin.php?page=wpamelia-calendar&amp;iframe=true&quot;&gt;&lt;/iframe&gt;&#039;;
 });
}
add_action(&#039;init&#039;, &#039;add_ameliacustomercalendar_to_myaccount_menu&#039;);</code></pre>]]></content:encoded>
					
					<wfw:commentRss>https://piglife.tw/technical-notes/woocommerce-amelia-calendar-iframe/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
