WordPress plugins and permalinks, how to use pretty links in your plugin

I’m working on a plugin, Read Offline, and one of the wishes was for url friendly links. After intensive googling, here’s how I did it:

“My Permalink Demo” plugin:

How to test the “My Permalink Demo” plugin

  • Save the code above as wp-content/plugins/ps_my_permalink.php, or get the plugin from WordPress.org
  • Activate the “My Permalink Demo” plugin
  • add the [mypermalink] or [mypermalink val="ipsum"] shortcode to a page or post

Tools

  • Debugging permalink errors is hard, I highly recommend Rewrite Analyzer (it helped me).

Changelog

1.0.2

  • Thanks to Paul, the plugin now only flushes the rewrite rules when needed.

1.0.1

  • Fixed a bug in my_permalink_url() that gave 404 for blogs in a subdirectory

1.0.0

  • Initial release

One thought on “WordPress plugins and permalinks, how to use pretty links in your plugin

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">