前言介紹
- 這款 WordPress 外掛「Script Logic」是 2014-06-15 上架。
- 目前有 10 個安裝啟用數。
- 上一次更新是 2014-07-10,距離現在已有 3951 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 2.8 以上版本才可以安裝。
- 有 2 人給過評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
admin | speed | style | script | conditional-tags |
內容簡介
這個外掛會列出所有JavaScript和樣式表,並帶有一個控制欄,讓您可以控制只在實際需要它們的頁面中包含CSS和JavaScript文件。文本欄讓您可以使用 WP 的條件標籤或任何一般PHP代碼。
注意:您引入的腳本邏輯會直接被評估。有權管理選項的任何人都有權添加任何代碼,包括惡意且可能破壞性的代碼。如果需要,可以使用可選過濾器‘script_logic_eval_override’自己的代碼繞過EVAL。(參見其他說明。)
編寫邏輯代碼
‘邏輯’欄中的文本可以是完整的PHP代碼,應當在您需要載入腳本時返回‘true’。如果文本中沒有‘return’,則會在開始時添加隱式‘return’,並在末尾添加‘;’。(這只是為了使像is_home()這樣的單個語句更方便。)
基礎知識
充分利用WP自己的條件標籤。您可以使用以下方法改變和組合代碼:
! (NOT)來反轉邏輯,例如:!is_home()當這不是首頁時為TRUE。
|| (OR)來組合條件。當X或Y為真時,X OR Y為TRUE。
&& (AND)使條件更具體。當X和Y都為TRUE時,X AND Y為TRUE。
WP論壇上有很多很好的代碼示例,網上的WP網站上也有。但是WP Codex也充滿了可以改編的好範例,例如測試文章是否在后代分類中。
範例
is_home() ——僅網誌主頁
!is_page('about') —— 除了這個特定的 WP ‘page’ 外的所有地方
!is_user_logged_in() —— 當用戶未登錄時顯示
is_category(array(5,9,10,11)) —— 一個給定類別ID的類別頁面
is_single() && in_category('baked-goods') —— 單個文章位於此類別中的類別頁面
strpos($_SERVER ['HTTP_REFERER'], "google.com")!=false —— 從谷歌搜索中單擊進入時載入的腳本
is_category() && in_array($cat, get_term_children( 5, 'category')) —— 類別頁面是類別5的後代
global $post; return (in_array(77,get_post_ancestors($post))); —— WP頁面是第77頁子頁面
global $post; return (is_page('home') || ($post->post_parent=="13")); —— 首頁或第13頁的子頁面
注意,在有明確‘return’的情況下,會在末尾加上額外的‘;’。
‘script_logic_eval_override’過濾器
在為每個腳本評估Script Logic代碼之前,Script Logic代碼的文本會通過此過濾器。如果過濾器返回布林結果,則使用此結果來確定是否載入腳本。返回TRUE以載入。
原文外掛簡介
This plugin lists all JavaScripts and Style sheets with a control field that lets you control CSS & JavaScript files to include only on the pages where you actually need them. The text field lets you use WP’s Conditional Tags, or any general PHP code.
NOTE: The script logic you introduce is evaluated directly. Anyone who has permission to manage options will have the right to add any code, including malicious and possibly destructive code. There is an optional filter ‘script_logic_eval_override’ which you can use to bypass the EVAL with your own code if needed. (See Other Notes).
Writing Logic Code
The text in the ‘Logic’ field can be full PHP code and should return ‘true’ when you need the script to load. If there is no ‘return’ in the text, an implicit ‘return’ is added to the start and a ‘;’ is added on the end. (This is just to make single statements like is_home() more convenient.)
The Basics
Make good use of WP’s own conditional tags. You can vary and combine code using:
! (NOT) to reverse the logic, eg !is_home() is TRUE when this is NOT the home page.
|| (OR) to combine conditions. X OR Y is TRUE when either X is true or Y is true.
&& (AND) to make conditions more specific. X AND Y is TRUE when both X is true and Y is true.
There are lots of great code examples on the WP forums, and on WP sites across the net. But the WP Codex is also full of good examples to adapt, such as Test if post is in a descendent category.
Examples
is_home() — just the main blog page
!is_page('about') — everywhere EXCEPT this specific WP ‘page’
!is_user_logged_in() — shown when a user is not logged in
is_category(array(5,9,10,11)) — category page of one of the given category IDs
is_single() && in_category('baked-goods') — single post that’s in the category with this slug
strpos($_SERVER['HTTP_REFERER'], "google.com")!=false — script to load when clicked through from a google search
is_category() && in_array($cat, get_term_children( 5, 'category')) — category page that’s a descendent of category 5
global $post; return (in_array(77,get_post_ancestors($post))); — WP page that is a child of page 77
global $post; return (is_page('home') || ($post->post_parent=="13")); — home page OR the page that’s a child of page 13
Note the extra ‘;’ on the end where there is an explicit ‘return’.
The ‘script_logic_eval_override’ filter
Before the Script Logic code is evaluated for each script, the text of the Script Logic code is passed through this filter. If the filter returns a BOOLEAN result, this is used instead to determine if the script should load. Return TRUE to load.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Script Logic」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
延伸相關外掛(你可能也想知道)
Redux Framework 》Redux – 快速在 WordPress 的 Gutenberg 中建立完整頁面, , 使用我們不斷更新的 WordPress 區塊模板、版面配置和模式強化 Gutenberg 編輯器。發現無限可能,...。
Loginizer 》Loginizer 是一個 WordPress 外掛,可幫助您對抗暴力攻擊,當 IP 地址達到最大重試次數時,該外掛會阻止其登錄。您可以使用 Loginizer 將 IP 地址列入黑名單...。
LightStart – Maintenance Mode, Coming Soon and Landing Page Builder 》這款 WordPress 外掛可讓您在維護網站時顯示一個維護頁面,讓訪客知道您的網站是暫時關閉的,也可以為新網站新增「即將到來」頁面,同時也可為現有網站創建登...。
Admin Menu Editor 》Admin Menu Editor 可讓您手動編輯儀表板菜單。您可以重新排序菜單,顯示/隱藏特定項目,修改權限等等。, 功能, , 更改菜單標題、URL、圖標、CSS 類等。, 通...。
White Label CMS 》White Label CMS 外掛針對開發者設計,提供客戶更具個性化且易於使用的內容管理系統。, 詳細瞭解 2.0 版本外掛變更,請參閱 Video User Manuals 網站。, 功能...。
Orbit Fox by ThemeIsle 》透過Orbit Fox,您可以使用各種模組擴充您的主題功能,例如社交媒體分享按鈕和圖示、自訂選單圖示、頁首和頁尾腳本、一鍵導入頁面模板、頁面建構器附加元件和...。
InfiniteWP Client 》InfiniteWP 可讓使用者從自己的伺服器管理無限數量的 WordPress 網站。, 主要功能:, , 自行託管系統:位於您自己的伺服器上,完全受您控制, 一鍵更新所有網站...。
Header and Footer Scripts 》如果您正在運行 WordPress 網站,早晚都需要將某種代碼插入到您的網站上。最有可能的是網頁分析代碼,例如 Google Analytics,或者是社交媒體腳本、某些 CSS ...。
Admin Columns 》這個 WordPress 外掛可以管理並整理文章、使用者、評論及媒體列表的欄位。它讓 WordPress 後台界面變得更美觀、明確。, , Admin Columns Pro, Admin Columns ...。
Nested Pages 》Nested Pages 是什麼?, , , 提供直覺且易於操作的拖放介面,以管理網頁結構及文章排序, 增強了快速編輯功能, 新增可編輯、可排序的樹狀表示網站頁面結構, 會...。
Disable REST API 》這是最全面的 WordPress REST API 存取控制外掛!, 輕鬆安裝,安裝後不需要額外設定即可使用。只需上傳並啟用,整個 REST API 將無法被一般訪客存取。, 但如...。
Advanced Custom Fields: Extended 》🚀 全方位增強套件,可改進WordPress和Advanced Custom Fields。此外掛旨在提供一個強大的管理框架,涵蓋了眾多改進和優化。, 此外掛需要至少 ACF Pro 5.8。,...。
Widget Shortcode 》這個短碼需要小工具的ID,但不需要猜測,外掛會為你生成代碼。如果你想要覆蓋小工具的標題,你可以使用 "title" 參數:, [widget id=”text-1″...。
All In One Favicon 》查看最新的WordPress交易以優化您的網站。, All In One Favicon為您的網站和管理頁面添加favicon。, 您可以使用您已經上傳的favicon或使用內置的上傳機制將fa...。
Add From Server 》這個外掛提供有限的支援。請不要期望有太多新功能或修正 bug。功能可能隨時被移除。, Add From Server 外掛旨在幫助緩解不好的網站主機所造成的困擾,讓您可...。