[WordPress] 外掛分享: Code Embed

前言介紹

  • 這款 WordPress 外掛「Code Embed」是 2009-04-04 上架。
  • 目前有 20000 個安裝啟用數。
  • 上一次更新是 2024-04-19,距離現在已有 29 天。
  • 外掛最低要求 WordPress 4.6 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 7.4 以上。
  • 有 44 人給過評分。
  • 論壇上目前有 1 個提問,問題解答率 100% ,不低,算是個很有心解決問題的開發者團隊了!

外掛協作開發者

dartiss |

外掛標籤

css | code | html | embed | javascript |

內容簡介

注意: WordPress 5.0 及以上版本的使用者請查看常見問題以了解如何在區塊編輯器中使用此外掛。
Code Embed 外掛允許您在文章中嵌入程式碼(JavaScript 和 HTML - 無法用於伺服器端的程式碼,如 PHP),而不會因編輯器改變內容而造成干擾。這非常有用,可以嵌入第三方腳本等。這個外掛被許多大型網站使用,包括 Mozilla 瀏覽器的官方網站。
主要功能包括...

將 HTML 或 JavaScript 嵌入文章或頁面──特別適用於嵌入影片!
使用 Widget Logic 外掛嵌入小工具
全域嵌入 allowser 可以在一篇文章或頁面中設置一些程式碼並從另一文章或頁面中存取
修改用於嵌入程式碼的關鍵字或識別碼使其符合您的需求
通過簡單搜索選項搜尋嵌入程式碼
添加簡單的後綴以將嵌入式影片轉換為響應式輸出
使用 URL 直接嵌入外部腳本
還有更多的功能!

本外掛的圖示由非常有才華的 Janki Rathod 設計 ♥️
👉 詳細的程式碼開發、預定增強功能和已知問題,請訪問 Github 頁面 👈
入門指南
下面是使用本插件的簡單方法...

安裝完插件後,開始撰寫一篇新文章或新頁面。
在「自訂欄位」框中輸入「CODE1」作為名稱,您要嵌入的程式碼作為值。儲存這個設定。
在您的文章中加入 {{CODE1}},這個程式碼將顯示在此位置。

當您檢視此文章或頁面時,{{CODE1}}會被嵌入您所要求的程式碼替代。
如果您無法在文章編輯器畫面中找到「自訂欄位」框的位置,請查看常見問題以獲得更多資訊。
這樣您就可以開始使用囉!如需更多的資訊和進階選項,請參照下方或參閱Elftronix 的使用指南。

選項設定
在管理選單中,有一個名為「Code Embed」的設定選項。
程式碼嵌入是透過特殊關鍵字進行的,您必須使用此關鍵字來唯一識別您想要嵌入程式碼的位置。此關鍵字包括一個開關識別碼(放在開頭),一個關鍵字,以及一個關閉識別碼。如果您希望在同一文章中嵌入多個程式碼,您也可以在關鍵字末端添加後綴。
在這個選項螢幕上,您可以指定您要使用的識別碼。 預設的開啟和關閉識別碼為百分比符號,關鍵字為 CODE。在這些說明中,所有範例中都將使用這些預設值。
此選項螢幕僅在具有管理選項或更高權限的使用者才可以使用。其他 Code Embed 選項則對具有編輯文章或更高權限的使用者開放。

嵌入
要在文章中嵌入程式碼,您需要在文章下方「自訂欄位」框中找到「Custom Fields」 meta 框。

原文外掛簡介

Code Embed allows you to embed code (JavaScript, CSS and HTML – it can’t be used for server-side code, such as PHP) in a post, without the content being changed by the editor. This is incredibly useful for embedding third-party scripts, etc. The plugin is used by many large sites, including Mozilla.
Key features include…

Add HTML or JavaScript to posts or pages – particularly useful for embedding videos!
Embed in widgets using the Widget Logic plugin
Global embedding allows you set up some code in one post or page and then access it from another
Modify the keywords or identifiers used for embedding the code to your own choice
Search for embedding code via a simple search option
Add a simple suffix to the embed code to convert videos to responsive output
Embed an external script directly using just the URL
And much, much more!

Iconography is courtesy of the very talented Janki Rathod.
Please visit the Github page for the latest code development, planned enhancements and known issues
Getting Started
To use this plugin, you need to have custom fields enabled on your site. If you’re using the block editor, you may need to switch this on first – please scroll down to the next section to learn how to do this. If you’re using the classic editor then you’ll find the custom fields at the bottom of the editor screen.
Although this plugin works for both posts and pages for simplicity I will simply refer to posts – bear in mind that pages work in the same way.
Once you have custom fields switched on, here’s how easy it is to use…

Once you have the plugin installed start a new post.
Scroll down to the bottom of the screen and look for the “Custom Fields” section.
Under “Add New Custom Field” enter a name of CODE1 and your embed code as the value
In your post content add {{CODE1}} where you wish the embed code to appear.

And that’s it – when the post viewed or previewed {{CODE1}} will be replaced with the code that you asked to be embedded.
This should get you started – for more information and advanced options please see below.. Alternatively, there’s a fantastic guide at Elftronix which I would recommend.
Using this plugin with the block editor (aka Gutenberg)
By default, custom fields are hidden inside the block editor but can be revealed.

Edit or create a post
Click the settings button (three dots) in the top, right-hand corner
Go to Preferences
Click the Panels tab
You will find a button to toggle the ‘Custom Fields’ meta box – make sure this is toggled to “on”
A button should appear titled “Enable & Reload” – you’ll need to click on that and wait for the page to reload before the custom fields will appear

Check out the screenshots for how the custom fields should look.
I can’t find the custom fields
For block editor users, I’m assuming you’ve done the above. For classic editor users, the custom fields should be present by default. In all cases they should appear at the bottom of the editor screen.
If they’re not present then you may have a theme or plugin that removes this or may have a problem with your WordPress installation – you will need to try the usual diagnostics to try and resolve this, including requesting help on the WordPress support forum.
Please bear in mind that the custom fields functionality is part of WordPress so it would be greatly appreciated if you don’t give me poor reviews in this situation as, I say, this component is not part of this plugin but, by using it, keeps this plugin simple to use and bloat-free 🙂
The Code Embed Options Screen
Whilst in WP Admin, if you go to Settings -> Code Embed, you’ll be able to access the options that are available for this plugin.
Code embedding is performed via a special keyword that you must use to uniquely identify where you wish the code to appear. This consist of an opening identifier (some that that goes at the beginning), a keyword and then a closing identifier. You may also add a suffix to the end of the keyword if you wish to embed multiple pieces of code within the same post.
From this options screen you can specify the above identifier that you wish to use. By default the opening and closing identifiers are percentage signs and the keyword is CODE. During these instructions these will be used in all examples.
The options screen is only available to those that with a capability of able to manage options or greater. All the other Code Embed menu options are available to users with a capability to edit posts or greater.
How to Embed Code
To embed in a post you need to find the meta box under the post named “Custom Fields”. If this is missing you may need to add it by clicking on the “Screen Options” tab at the top of the new post screen.
Now create a new custom field with the name of your keyword – e.g. CODE. The value of this field will be the code that you wish to embed. Save this custom field.
Now, wherever you wish the code to appear in your post, simply put the full identifier (opening, keyword and closing characters). For example, {{CODE}}.
If you wish to embed multiple pieces of code within a post you can add a suffix to the keyword. So we may set up 2 custom fields named CODE1 and CODE2. Then in our post we would specify either {{CODE1}} or {{CODE2}} depending on which you wish to display.
Don’t forget – via the options screen you can change any part of this identifier to your own taste.
How to Embed Code from an External URL
If you specify a URL within your post, surrounded by your choice of identifiers, then the contents of the URL will be embedded within your post.
Obviously, be careful when embedding a URL that you have no control over, as this may be used to hijack your post by injecting, for example, dangerous JavaScript.
For example, using the default options you could embed the contents of a URL using the following method…
{{http://www.example.com/code.php}}

or
{{https://www.example.com/code.html}}

How to Use Global Embedding

You can also create global embeds – that is creating one piece of embed code and using it in multiple posts or pages.
To do this simply make reference to an already defined (but unique) piece of embed code from another post or page.
So, let’s say in one post you define a custom field named CODE1. You can, if you wish, place {{CODE1}} not just in that post but also in another and it will work.
However, bear in mind that the embed code name must be unique – you can’t have defined it in multiple posts otherwise the plugin won’t know which one you’re referring to (although it will report this and list the posts that it has been used in).
In the administration menu there is a sidebar menu named “Tools”. Under this is a sub-menu named “Code Search”. Use this to search for specific embed names and it will list all the posts/pages that they’re used on, along with the code for each.
Embedding in Widgets
Natively you cannot use the embed facilities within sidebar widgets. However, if you install the plugin Widget Logic then Code Embed has been set up to make use of this and add the ability.

Install Widget Logic and activate.
In Administration, select the Widgets page from the Appearance menu. At the bottom there will be a set of Widget Logic options.
Ensure Use ‘widget_content’ filter is ticked and press Save.

Although you cannot set up embed code within a widget you can make reference to it, for example by writing {{CODE1}} in the widget.
Responsive Output Conversion
Responsive output is where an element on a web page dynamically resizes depending upon the current available size. Most video embeds, for instance, will be a fixed size. This is fine if your website is also of a fixed size, however if you have a responsive site then this is not suitable.
Code Embed provides a simple suffix that can be added to an embed code and will convert the output to being responsive. This works best with videos.
To use, when adding the embed code onto the page, simply add _RES to the end, before the final identifier. For example, {{CODE1_RES}}. The _RES should not be added to the custom fields definition.
This will now output the embedded code full width, but a width that is dynamic and will resize when required.
If you don’t wish the output to be full width you can specify a maximum width by adding an additional _x on the end, where x is the required width in pixels. For example, {{CODE1_RES_500}} this will output CODE1 as responsive but with a maximum width of 500 pixels.
It should be noted that this is an experimental addition and will not work in all circumstances.
Embedding in excerpts
By default embed code will not appear in excerpts. However, you can switch this ability on via the Code Embed options screen. If you do this then the standard rules of excerpts will still apply, but now once the code embed has applied – for example, excerpts are just text, a specific length, etc.
Reviews & Mentions
“Works like a dream. Fantastic!” – Anita.
“Thank you for this plugin. I tried numerous other iframe plugins and none of them would work for me! This plugin worked like a charm the FIRST time.” – KerryAnn May.
Embedding content – WSD Blogging Server.
Animating images with PhotoPeach – Cómo hago.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Code Embed」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0 | 1.1 | 1.2 | 1.3 | 1.4.1 | 1.5.1 | 1.6.1 | 2.0.2 | 2.1.2 | 2.2.2 | 2.3.4 | 2.3.5 | 2.3.6 | 2.3.7 | 2.3.8 | 2.3.9 | trunk |

延伸相關外掛(你可能也想知道)

  • WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager 》插入標頭和頁腳 + 完整的 WordPress 代碼片段外掛, WPCode (前稱为 WPBeginner 的 "插入標頭和頁腳")是使用率超过 100 万个网站的 WordPress 代码片段外掛中...。
  • Code Snippets 》Code Snippets 是在您的網站上運行程式碼片段的簡單,清潔和簡單的方法。它消除了將自定義片段添加到您的佈景主題的 functions.php 檔案的需求。, 現在提供 C...。
  • Simple Custom CSS Plugin 》無需麻煩地將自訂 CSS 新增到 WordPress 網站中。, 這是一個易於使用的 WordPress 外掛,可以添加自訂 CSS 樣式以覆寫外掛和佈景主題的預設樣式。該外掛旨在...。
  • Scripts n Styles 》這個外掛讓管理員用戶能夠將自訂的 CSS 和 JavaScript 直接添加到個別文章、頁面或任何註冊的自訂文章類型中,也可以將類別添加到 body 標籤和文章容器中。還...。
  • SyntaxHighlighter Evolved 》現在支援 WordPress 5.0 中的新區塊編輯器!, SyntaxHighlighter Evolved 讓您可以輕鬆地在網站上張貼帶有語法加亮功能的程式碼,而不會失去格式或做任何手動...。
  • PHP Everywhere 》注意:此外掛更新至 3.0.0 版本是一項重大變更,將移除 [php_everywhere] 短代碼和小工具。請透過外掛設定頁面中的升級嚮導,將原本的代碼轉換為 Gutenberg ...。
  • WP Coder – Powerful HTML, CSS, JS and PHP Injection 》WP Coder 是一個用於在網站添加自定義代碼的外掛程式。您可以輕鬆地將 HTML、CSS 和 JS 代碼添加到網站頁面中。此外掛程式非常適合連接各種腳本或樣式,使網...。
  • Highlighting Code Block 》「Highlighting Code Block」外掛可讓你以一個點擊的方式添加一個有語法突顯的程式碼區塊。, 它支援「區塊編輯器」和「傳統編輯器」。, (不過,我們建議在「...。
  • Code Syntax Block 》代碼語法區塊(Code Syntax Block)擴充了 WordPress 區塊編輯器,使用 Prism 語法高亮工具為核心代碼區塊添加了語法高亮支持。, Prism 語法高亮工具在前端執...。
  • Advanced CSS Editor 》Advanced CSS Editor 是一個輕量級的外掛,它讓你可以在即時編輯器中為不同設備(桌面、平板、手機)撰寫不同的 CSS 代碼,並且可以即時查看結果。, 因此,只...。
  • Machete 》Machete是一個簡單的工具套件,可以盡可能節省資源來解決常見的WordPress煩惱。Machete並不適用於每一種使用情況,但若您使用Machete,會需要較少的外掛程式...。
  • Code Widget 》Code Widget 是一個簡單的小工具,允許您插入任意的文字/HTML,執行 PHP 程式碼或 Short Code。此小工具解析 PHP 程式碼為簡單文字等等。, 只有擁有未過濾的 ...。
  • Code Block Pro – Beautiful Syntax Highlighting 》展示你美麗的程式碼,不僅僅是顯示它!這個版塊外掛提供編輯程式碼塊的功能,直接運行你的程式碼,使用與受歡迎的 VS Code 編輯器相同的渲染引擎。此外掛提供...。
  • Advance Custom HTML – Code editor block for WordPress 》這是一款用來專業編寫 HTML 代碼的高級 HTML 編輯器,提供不同的樣式、縮排與更多功能。, Advance Custom HTML 是一款功能強大、彈性十足的區塊外掛,讓您可...。
  • WP-Syntax 》WP-Syntax 提供乾淨的語法突顯,使用 GeSHi,支援多種流行的語言,包括有或沒有行號的語法突顯,可以在從瀏覽器中複製程式碼片段時保持格式。, 它通過運行早...。

文章
Filter
Apply Filters