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

3 thoughts on “WordPress plugins and permalinks, how to use pretty links in your plugin

  1. Kenneth

    Hei Per, Really helpful plugin. I was looking into this and felt my brain getting fried, I am really happy I stumbled onto your plugin. :-)

    I have a guestion though, maybe it´s a stupid one, but I hope you can help me. In your code for the function my_permalink_parse_request, where I can add what I want to preview. I want to preview a page witch have another shortcode tag in it witch is specified in my code. So that it previews the hole wordpress page etc.. I can´t seem to understand how to do this by the way you have coded this? Can you shed some light please?

    Reply
  2. Kenneth

    Just a little additional comment. As an example for the plugin, it would be nice to know how you would use my_permalink_parse_request to call so that it will print out the result back to the page that you have your [mypermalink] on to or another page, but the most important is that it will actually print all the template of the theme that you are currently installed. Does that make sense? Please let me know if you want me to clarify. :-)

    Reply

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="">