前言介紹
- 這款 WordPress 外掛「Scripts To Footer」是 2013-01-26 上架。
- 目前有 9000 個安裝啟用數。
- 上一次更新是 2023-12-18,距離現在已有 503 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 5.3 以上版本才可以安裝。
- 外掛要求網站主機運作至少需要 PHP 版本 7.4 以上。
- 有 37 人給過評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
head | speed | footer | javascript | performance |
內容簡介
n
這個小型外掛程式可以把腳本搬至頁面底部的 JavaScript 塊中。請注意,您必須擁有使用wp_enqueue_scripts正確的外掛和佈景主題來實現此目的。
您可以通過所需的文章/頁面編輯螢幕 metabox 直接停用此外掛。
您可以透過設定頁面在特定存檔頁面(部落格頁面、搜尋頁面、文章類型和分類檔案)停用此外掛。
出了問題了嗎?嘗試通過 "設定 > 移動腳本至底部 > "將jQuery放回頁首的選框中,重新啟用頁首腳本。如果沒有作用,請參考以下步驟,使用 stf_exclude_scripts 過濾器來解決問題。
請在 GitHub 上檢查這個外掛的 說明文檔或以下的簡易步驟。
將特定腳本保留在頁首
從版本 0.6 開始,您現在可以在頁首保留特定腳本。注意:這將列印出它所依賴的任何腳本(如果您想在頁首保留jquery-effects-core,您也會得到頁首的jQuery,因此無需添加兩個)。
對於 jQuery,請查看設定頁面選項,因為它是一個普遍的請求,因此我們將其內置到設定中。
對於任何其他腳本,使用此過濾器:
add_filter('stf_exclude_scripts', 'jdn_header_scripts', 10, 1);
function jdn_header_scripts($scripts)
{
$scripts[] = 'backbone'; //將'backbone'替換為腳本slug
return $scripts;
}
您需要正確的腳本slug,該slug在腳本註冊時使用,當該腳本已排隊時,該腳本將僅被列印到頁首。查看隨WordPress「開箱即用」註冊的腳本。
注意:從版本 0.6.3開始,條件標記將與過濾器 stf_exclude_scripts 可使用。
自訂文章類型支援
如果您熟悉代碼,則可以使用 scripts_to_footer_post_types 過濾器來更改套用此方法的文章類型(預設僅套用於頁面和文章)。例如,如果您有一個名為"project"的自訂文章類型,您可以使用以下方式通過文章類型過濾器添加對此 metabox 的支援:
function stf_add_cpt_support($post_types) {
$post_types[] = 'project';
return $post_types;
}
add_filter('scripts_to_footer_post_types', 'stf_add_cpt_support');
通過過濾器排除頁面/文章/樣板
從版本 0.5 開始,您可以使用核取方塊選項在特定頁面/文章停用插件的操作,或者使用過濾器(從版本 0.6 開始更新)。該過濾器還傳遞了文章/頁面ID,如果有的話(存檔模板沒有id!)。
例如,對於"頁面"文章類型:
function stf_exclude_my_page($exclude_page, $post_id) {
if( is_front_page() ) {
$exclude_page = 'on'; //這將打開 "排除" 選項
}
返回 $exclude_page;
}
add_filter('stf_page', 'stf_exclude_my_page');
將 stf_page 替換為 stf_post 以獲取文章,或使用您的自訂文章類型的 slug。例如,名為"project"的文章類型可以使用 stf_project 過濾器過濾。
更多文檔
原文外掛簡介
This small plugin moves scripts to the footer. Note that this only works if you have plugins and a theme that utilizes wp_enqueue_scripts correctly.
You can disable the plugin on specific pages and posts directly via the post/page edit screen metabox.
You can disable the plugin on specific archive pages (blog page, search page, post type and taxonomy archives) via the settings page.
Everything Broken? Try placing jQuery back into the header via Settings > Scripts to Footer, “Keep jQuery in the Header” checkbox. If that doesn’t work, refer to the walkthrough below for using the stf_exclude_scripts filter for the script that is causing the issue.
Check out the documentation on GitHub or some quick walkthroughs below.
Keeping specific Scripts in the Header
As of version 0.6 you can now keep specific scripts in the header. Note: this will print any scripts they depend on as well (if you want to keep jquery-effects-core in the header, you’ll also get jQuery in the header, so no need to add both).
Specifically for jQuery, see the settings page option, as it is a common request we’ve built it into the settings.
For any other scripts, use this filter:
add_filter( 'stf_exclude_scripts', 'jdn_header_scripts', 10, 1 );
function jdn_header_scripts( $scripts ) {
$scripts[] = 'backbone'; // Replace 'backbone' with the script slug
return $scripts;
}
You will need the correct script slug, which is used when the script is registered, and the script will only be printed into the header if it’s enqueued. Check out the scripts that come registered out-of-the-box with WordPress.
Note: As of version 0.6.3, conditional tags will work with the stf_exclude_scripts filter.
Custom Post Type Support
If you’re comfortable with code you can use the scripts_to_footer_post_types filter to change the post types this applies to (it only applies to pages and posts by default). For example, if you have a custom post type called “project” you could add support for this metabox via the post type filter like this:
function stf_add_cpt_support( $post_types ) {
$post_types[] = 'project';
return $post_types;
}
add_filter( 'scripts_to_footer_post_types', 'stf_add_cpt_support' );
Excluding Pages/Posts/Templates Via Filter
As of version 0.5 you can either use the checkbox option to disable the plugin’s action on a specific page/post, or you can utilize a filter (updated with version 0.6). The filter also passes the post/page id, if there is one (archive templates don’t have ids!).
For example, for the “page” post type:
function stf_exclude_my_page( $exclude_page, $post_id ) {
if( is_front_page() ) {
$exclude_page = 'on'; // this turns on the "exclude" option
}
return $exclude_page;
}
add_filter( 'stf_page', 'stf_exclude_my_page' );
Replace stf_page with stf_post for posts, or the slug of your custom post type. For instance, a post type called “project” can be filtered with stf_project.
More Documentation
View this plugin on GitHub.
View on GitHub
View this plugin on GitHub.
Please feel free to open a Github Issue to report conflicts or goto the WP.org support forum. If there is something wrong with Scripts-to-Footer, we’ll update it. However, if it’s a another plugin or theme we can only contact the developer with the issue to attempt to resolve it.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Scripts To Footer」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
0.1 | 0.2 | 0.3 | 0.5 | 0.6.0 | 0.6.1 | 0.6.2 | 0.6.3 | 0.7.0 | 0.7.1 | 0.7.2 | trunk | 0.6.4.1 |
延伸相關外掛(你可能也想知道)
Header Footer Code Manager 》Header Footer Code Manager by 99 Robots 是一個簡易的介面,可將片段添加到頁面的標頭或頁腳或內容上方或下方。, 優點, , 無需擔心因添加代碼而不小心使網...。
Head, Footer and Post Injections 》關於 WordPress SEO 和 Facebook Open Graph:我對 Yoast 的邀請讓我刪除我的外掛非常不滿,但實際上並不需要。, 點擊此處了解更多。, 頁首和頁尾代碼, 為什...。
Insert Headers And Footers 》WP Headers and Footers 外掛程式可以協助您在 WordPress 網站的頁首和頁尾中插入程式碼,例如 Google Analytics 追蹤碼、Facebook 像素碼、Google Optimize ...。
Header and Footer Scripts 》如果您正在運行 WordPress 網站,早晚都需要將某種代碼插入到您的網站上。最有可能的是網頁分析代碼,例如 Google Analytics,或者是社交媒體腳本、某些 CSS ...。
Head & Footer Code 》Head & Footer Code 插件可以讓你在不是開發人員的情況下,添加自定義代碼片段(JavaScript、CSS 或 HTML)到網頁中。您可以將代碼放置在 (...。
Remove Footer Credit 》在網頁渲染之前移除或替換頁腳標誌(或頁面中的任何文本或 HTML )。使用此外掛程式,無需修改代碼,例如 footer.php,否則可能會導致您的網站崩潰,或者新的...。
Visual Footer Credit Remover 》使用滑鼠點擊即可移除或替換任何 WordPress 主題的頁腳文字。。
SOGO Add Script to Individual Pages Header Footer 》已經在 Gutenberg 上進行測試, 創建一個簡單的方式,為個別頁面、文章或自訂文章類型的標題和頁腳添加 JavaScript 代碼,, 例如: 在感謝頁面上添加轉換代碼, ...。
Footer Putter 》, Footer Putter 可以創建兩個小工具:Footer Putter 版權小工具和 Footer Putter 商標小工具, 包括您的網站認證,以證明您的業務符合行業的要求標準, 創建一...。
Yoast Breadcrumbs 》這個外掛可以輕鬆地在你的模板中添加面包屑。如果你正在使用其中一個支援的 WordPress 框架,只需要啟用這個外掛,並勾選「嘗試自動添加」框即可。如果你沒有...。
Remove Footer Credits & Powered By 》使用這個外掛,可以移除主題底部的標籤欄與所有頁面底部的連結,只需安裝並啟用此外掛即可完成。不需要繁複的設置或額外的步驟。, 注意:啟用外掛後,您可能...。
Simple Header Footer HTML 》這個外掛可以讓您的使用者插入自訂的 CSS,或是加入自訂的標頭或 JavaScript 到網站中,而不必編輯主題檔案。與類似的標頭/底部外掛不同的是,這個外掛的設計...。
Storefront Footer Bar 》這款簡單的外掛增加了一個全寬度的小工具區域,位於預設的列式 Storefront 頁腳小工具區域上方,您可以透過自定義器添加背景圖像並通過「自訂」介面微調顏色...。
PRyC WP: Add custom content to post and page (top/bottom) 》在文章或頁面上添加自訂內容(頂部/底部)。您可以使用文本、HTML、短代碼和JavaScript。簡單而有效... 。
Speed Up – JavaScript To Footer 》這個小巧的 WordPress 外掛(2 KB)將 JavaScript 移到頁尾,增加頁面載入速度。, 注意:此外掛只會在其他外掛和主題正確添加 JavaScripts 的情況下運作。, ...。