[WordPress] 外掛分享: WP Hydra

首頁外掛目錄 › WP Hydra
WordPress 外掛 WP Hydra 的封面圖片
1,000+
安裝啟用
★★★★★
5/5 分(10 則評價)
2637 天前
最後更新
問題解決
WordPress 4.0+ v1.2 上架:2014-12-16

內容簡介

WP Hydra 的目的非常簡單明瞭。假設您擁有一個 WordPress 網站,託管於example.com。同時,您也購買了 example.net 和 example.org,希望它們也可以使用相同的網站(同一個安裝),但是使用特定的域名以保持一致的使用者體驗。換句話說,您希望您的 WordPress 安裝可以在多個域名下解析和瀏覽。WP Hydra 可以幫助您實現這一點。

將多個網址指向同一個網站是指從多個不同的域名將流量引導到您的網站的好方法。有兩種實現方式:將其中一個網址重新導向到主要域名,或停放域名,使這些域名指向您的主要域名。

當在地址欄中輸入網址時,重新導向是指將訪問者發送到不同於輸入的網站(或 URL)的網站。如果這是您的首選情況,那麼 WP Hydra 就不需要您使用。

停放域名與重新導向相同,只是顯示在地址欄上的網站名稱不會更改。您可以將多個域名停放到同一個頁面。在停放域名之前,它們必須在有效的域名註冊機構進行註冊。而且,您需要確保名稱伺服器與您的主要網域相同(即您指向的域名)。

多個域名指向同一個網站後,您需要啟用外掛程式。不需要進行其他配置或設置。這將確保 css、js、圖像和連結,它們原本用於原始域與現在用於當前正在查看的域的相同性。這將確保用戶保持在他們原來訪問的站點上,提供一致的使用體驗。

配置

您只需要確保多個域名指向相同的託管和物理位置。

完成後,只需安裝並啟用外掛程式 - 不需要進行其他配置。

進一步自定義 - 過濾器

如果您有一些自定義內容,並且希望其中的 URL 支持多個域名,可以使用 wp_hydra_content 過濾器,例如:

// 我們假設您具有 $content 中的某些內容
$content = apply_filters( 'wp_hydra_content', $content );

如果您有一些自定義 URL 并希望它們支持多個域名,可以使用 wp_hydra_domain 過濾器,例如:

// 我們假設您具有 $content 中的某些內容
$url = apply_filters('wp_hydra_domain', $url);

開發人員的進一步自定義

由於 $wp_hydra 物件是全域的,您只需在其上調用 remove_action() 或 remove_filter 即可輕鬆取消任何默認功能。以下示例將刪除內容的 WP Hydra 行為,但僅針對存檔頁面上的 the_content() 調用:

add_action( 'wp_loaded', 'some_example_here' );
function some_example_here() {
global $wp_hydra;
if( is_archive() ) {
remove_filter( 'the_content', array( $wp_hydra, 'setup_content' ) );
}
}

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.2) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「WP Hydra」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

WP Hydra has a quite straightforward purpose. Say you have a WordPress site, hosted on example.com. You’ve also purchased example.net and example.org, and you want them to also use the same website (the same installation), but to persist with that particular domain to have a consistent user experience. In other terms, you want your WordPress installation to be resolved and browsed at multiple domains. WP Hydra can help you with this.
Pointing multiple URLs to the same website is a good way to direct traffic to your site from several different domain names. You can accomplish this in two ways: either redirect one of the URLs to your primary domain, or park the domains, which point these domains towards your primary domain.
A redirect occurs when typing a web address in the address bar sends a visitor to another website (or URL), different from the one typed in. If this is your preferred case, then WP Hydra will not be of any need to you.
Parking a domain does the same thing as a redirect, except that the website name shown on the address bar does not change. You can park several domains to the same page. They have to be registered with a valid domain registrar before you can park them. Also, you’ll need to make sure the nameservers are the same as your primary domain (the domain that you are pointing towards).
Once your multiple domains point to the same website, you have to activate the plugin. No additional configuration or setup is required. This will make sure that the css, js, images and links that are leading to the original domain are now leading to the domain that you’re currently viewing. This will assure that the users remain on the site that they’ve originally visited, providing consistent experience.
Configuration
You only need to make sure that your multiple domains point to the same hosting, and to the same physical location on your hosting account.
Once this is done, simply install and activate the plugin – no additional configuration is needed.
Further customization – filters
If you have some custom content and you want the URLs within it to support multiple domains, you can use the wp_hydra_content filter, like this:
// we assume that you have some content in $content
$content = apply_filters( 'wp_hydra_content', $content );

If you have some custom URLs somewhere and you want them multiple domains, you can use the wp_hydra_domain filter, like this:
// we assume that you have some content in $content
$url = apply_filters('wp_hydra_domain', $url);

Further customization for developers
Since the $wp_hydra object is global, you can easily unhook any of the default functionality by simply calling remove_action() or remove_filter on it. The following example will remove the WP Hydra behavior of the content, but only for the_content() calls on the archive page:
add_action( 'wp_loaded', 'some_example_here' );
function some_example_here() {
global $wp_hydra;
if( is_archive() ) {
remove_filter( 'the_content', array( $wp_hydra, 'setup_content' ) );
}
}

延伸相關外掛

文章
Filter
Apply Filters
Mastodon