內容簡介
Hum 是一個針對 WordPress 的個人網址短縮器,旨在提供短網址給您個人內容,無論是托管在 WordPress 上還是其他地方。例如,與其使用 WordPress 文章的長網址,例如 http://willnorris.com/2011/01/hum-personal-url-shortener-wordpress,您可以使用短網址,如 http://willnorris.com/b/FJ。此外,如果您有自訂的短網址域名,您可以進一步縮短網址,例如 http://wjn.me/b/FJ。一旦啟用外掛,頁面或文章的短連結可以在 WordPress 管理工具欄中的「短連結」項目中找到。
WordPress 文章 ID 是使用特定為簡潔易讀而優化的 NewBase60 編碼方案縮短的,具有內置錯誤校正功能,可針對常見混淆字元,例如「1」、「l」和「I」。
Hum 不是一個類似於 http://bit.ly 或 http://goo.gl 的通用網址短縮器。相反,它是專為個人內容設計的短網址。
有關使用個人網址縮短器的原因,請參閱 Tantek Celik 的 Whistle 頁面,該頁面是 Hum 的靈感來源。
開發人員文件
添加 Amazon 廣告聯盟 ID
如果您想在 /i/ 重定向網址中包含 Amazon 廣告聯盟 ID,請實施 amazon_affiliate_id 過濾器。例如:
add_filter('amazon_affiliate_id', create_function('', 'return "willnorris-20";'));
其他本地類型
Hum 預設僅註冊 b、t、a 和 p 前綴用於由 WordPress 本地提供。如果您想註冊其他前綴,請實現 hum_local_types 過濾器。例如,如果您還想註冊「p」以供照片使用:
function myplugin_hum_local_types( $types ) {
$types[] = 'p';
return $types;
}
add_filter('hum_local_types', 'myplugin_hum_local_types');
這將告訴 Hum 從 WordPress 服務任何 /p/{id} 的 URL。此外,您還需要指示 Hum 使用該特定內容類型的前綴。這裡,我們註冊了用於照片的「p」。
function myplugin_hum_type_prefix( $prefix, $post_id ) {
$post = get_post( $post_id );
if ( $post->post_type == 'attachment' &&
strpos($post->post_mime_type, 'image') === 0 ) {
$prefix = 'p';
}
return $prefix;
}
add_filter('hum_type_prefix', 'myplugin_hum_type_prefix', 10, 2);
簡單重定向
您可以使用一行 PHP 代碼來重定向屬於特定前綴的所有流量,只需實現 hum_redirect_base_{type} 過濾器,其中 {type} 是要重定向的前綴。例如,我把所有 /w/ 的 URL 重定向到 wiki.willnorris.com,使用以下代碼:
add_filter('hum_redirect_base_w',
create_function('', 'return "http://wiki.willnorris.com/";'));
外掛標籤
開發者團隊
原文外掛簡介
Hum is a personal URL shortener for WordPress, designed to provide short URLs to your personal content, both hosted on WordPress and elsewhere. For example, rather than a long URL for a WordPress post such as http://willnorris.com/2011/01/hum-personal-url-shortener-wordpress, you could have a short URL like http://willnorris.com/b/FJ. Additionally, if you have a custom domain for short URLs, you can shorten things further like http://wjn.me/b/FJ. Once the plugin is enabled, the shortlink for a page or post can be found in the “Shortlink” item in the WordPress Admin Bar.
WordPress post IDs are shortened using the NewBase60 encoding scheme which is specifically optimized for brevity and readability, with built-in error correction for commonly confused characters like ‘1’, ‘l’, and ‘I’.
Hum is not designed as a general purpose URL shortener along the lines of http://bit.ly or http://goo.gl. Rather, it is specifically intended as a personal shortener for your own content.
Read more about the reasoning for a personal URL shortener at Tantek Celik‘s page for Whistle, which served as the inspiration for Hum.
Developer Documentation
Adding your Amazon Affiliate ID
If you’d like to include your Amazone Affiliate ID in the /i/ redirect URLs, implement the amazon_affiliate_id filter. For example:
add_filter('amazon_affiliate_id', fn() => "willnorris-20");
Additional Local Types
Out of the box, Hum only registers the b, t, a and p prefix to be served locally by WordPress. If you would like to register additional prefixes, implement the hum_local_types filter. For example, to include ‘p’ as well for photos:
function myplugin_hum_local_types( $types ) {
$types[] = 'p';
return $types;
}
add_filter('hum_local_types', 'myplugin_hum_local_types');
This will tell Hum to serve any /p/{id} URLs from WordPress. Additionally, you’ll want to instruct Hum to use your prefix for that particular content type. Here, we’re registering ‘p’ which is normally used for photos.
function myplugin_hum_type_prefix( $prefix, $post_id ) {
$post = get_post( $post_id );
if ( $post->post_type ## 'attachment' &&
strpos($post->post_mime_type, 'image') =## 0 ) {
$prefix = 'p';
}
return $prefix;
}
add_filter('hum_type_prefix', 'myplugin_hum_type_prefix', 10, 2);
Simple Redirect
You can redirect all traffic for a prefix using a single line of PHP my implementing the hum_redirect_base_{type} filter where {type} is the prefix to redirect. For example, I redirect all /w/ URLs to wiki.willnorris.com using:
add_filter('hum_redirect_base_w', fn() => "http://wiki.willnorris.com/");
