這個外掛並未在最新的 3 個 WordPress 主要版本上進行測試。開發者可能不再對這個外掛進行維護或提供技術支援,並可能會與更新版本的 WordPress 產生使用上的相容性問題。

Absolute-to-Relative URLs

外掛說明

If you were to use this on a website like http;//example.com/test/testing/, you would get results like these:

    • Before: http;//example.com/test/another-test/#anchor
    • After: ../another-test/#anchor
    • Before: http;//example.com/wp-content/themes/twentyten/style.css
    • After: /wp-content/themes/twentyten/style.css
    • Before: https;//example.com/wp-content/themes/twentyten/style.css
    • After: https;//example.com/wp-content/themes/twentyten/style.css
    • Before: http;//google.com/test/
    • After: //google.com/test/
    • Before: ../../../../../../../../#anchor
    • After: /#anchor
    • After ($output_type=1): ../../#anchor

All string parsing. No directory browsing.

If you’re looking for a plugin that will automatically convert all URLs on your WordPress site, instead check out my other plugin, WP-HTML-Compression.
Before you copy this code and add it into your own, keep in mind that there will probably be future updates. Keeping the code within an installed plugin will make sure that you’re notified.

安裝方式

  1. Download the plugin (zip file).
  2. Upload and activate the plugin through the “Plugins” menu in the WordPress admin.

常見問題集

Why isn’t this automatic?

Check out WP-HTML-Compression instead.

How does this work?

Just use absolute_to_relative_url($url).

Will this plugin work for WordPress version x.x.x?

This plugin has only been tested with versions of WordPress as early as 3.2. For anything older, you’ll have to see for yourself.

使用者評論

這個外掛目前沒有任何使用者評論。

參與者及開發者

以下人員參與了開源軟體〈Absolute-to-Relative URLs〉的開發相關工作。

參與者

將〈Absolute-to-Relative URLs〉外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

變更記錄

0.3.4

  • Empty, hash-only anchors ("#") are no longer invalidated to "/"

0.3.3

  • JavaScript URIs ("javascript:") are no longer invalidated as paths

0.3.2

  • Data URIs ("data:") are no longer invalidated as paths

0.3.1

  • Domains with and without “www.” are no longer considered to be identical by default, but can still be overridden

0.3

  • Scheme-relative URLs (//domain.com) now supported on input and output
  • Cleans up the ports and paths of external URLs
  • Optionally, output only host-relative URLs (/root-dir/)
  • Speed optimizations
  • Minor bug fixes

0.2

  • Path-relatve URLs (../), or parenting, now supported on input and output
  • Differentiates schemes/protocols, usernames, passwords, hosts, ports, paths, resources/files, queries and fragments/hashes
  • Considers domains with and without “www.” to be identical, and can be overridden
  • Outputs the shortest url (host- or path-relative) by default, and can be overridden
  • Custom site URL support, but only with a separate new Absolute_to_Relative_URLs() instance

0.1

  • Initial release