New Plugin: Custom Post Permalinks

I just released a new plugin for WordPress this morning. It’s called ‘Custom Post Permalinks’. Custom Post Permalinks gives you the option of customizing the permalinks used by your non-hierarchical custom post types (post types that act like blog posts). The default permalink structure used for custom post types is /post_type/name/, but with this plugin you can easily modify it to something more like /post_type/year/month/name/. All of this is done through the admin section’s normal permalinks settings page, so you can manage all your permalinks in one place. Easy as pie!

Even better: if you add things like year and month (or day, hour and second!) to your custom permalink settings, it automatically sets up those archives! It also automatically adds permalink structures for feeds, comments, and pagination!

I’ll be setting up a static page for the plugin soon. Keep your eyes peeled.

Special thanks go out to Aaron Jorbin (@aaronjorbin) for helping me with the code. The plugin would be nowhere near where it is now without him. Also, if I hadn’t known he might be looking at it, I may not have documented it as thoroughly as I did…
;)

Kansas boy transplanted to DC. English major transplanted to web development. Lover of things.

25 Comments

  1. axe · August 14, 2010

    Can we create Permalinks extantion , We need Permalinks extantion .html

    mysitename.com/postname.html

    and

    mysitename.com/pagename.html

    can it possible ?

    if yes then tell me how

    Thanks

    • John P. Bloch · August 14, 2010

      Yes, it is possible to throw an extension onto any permalink. /%post_type%/%year%/%monthnum%/%postname%.html Will give you the .html extension. You’ll also need to disable trailing slashes by adding this to your theme’s functions.php file:

      add_action( 'init', create_function( '$a', 'global $wp_rewrite; $wp_rewrite->use_trailing_slashes = false;' ) );

      • Kul_anurag · November 23, 2010

        can you just give me full code. I not know where i update that code on function.php

  2. Gennadiy · August 15, 2010

    Good day
    on screenshot i saw plugin called wp-employee – where can i find a description of it?
    Thank you

  3. axe · August 16, 2010

    Hello,

    I have try to add code in functions.php

    that code in

    add_action( ‘init’, create_function( ‘$a’, ‘global $wp_rewrite; $wp_rewrite->use_trailing_slashes = false;’ ) );

    also change in

    Custom Structure : /%postname%.html

    on mouse on link its show .html extension on links, but when we click on post or page links its show error
    its show in address bar

    http://mydomain.com/about-us.html

    error is :

    The page cannot be found

    The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
    Please try the following:

    • axe · August 16, 2010

      Hello,

      working with windows hosting
      I have try on Linux hosting its working with Linux hosting, but not working with windows hosting

    • John P. Bloch · August 16, 2010

      I do not have Windows hosting, so cannot test these things on a Windows environment and do not offer support for Windows issues. If having the .html extension is really that important for you, I suggest you switch your host to a Linux server.

  4. axe · August 18, 2010

    Hello,

    I have try to add code in functions.php

    that code in

    add_action( ‘init’, create_function( ‘$a’, ‘global $wp_rewrite; $wp_rewrite->use_trailing_slashes = false;’ ) );

    also change in

    Custom Structure : /%postname%.html

    on mouse on link its show .html extension on links, but when we click on post or page links its show error
    its show in address bar

    http://mydomain.com/about-us.html

    error is :

    The page cannot be found

    The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
    Please try the following:

  5. Pearson Comm · August 24, 2010

    I installed & activated your plugin but the options do not show up on the permalinks page. I’m using wordpress 3.01 network setup

  6. Pearson Comm · August 24, 2010

    I installed & activated your plugin but no options show up on the permalinks page.

  7. John P. Bloch · August 24, 2010

    My plugin does not support hierarchical post types. If they’re non-hierarchical, let me know, and I’ll look into it.

  8. Milan · September 18, 2010

    if you add things like year and month (or day, hour and second!) to your custom permalink settings, it automatically sets up those archives

    I have different experience. My default permalink structure is /blog/%year%/%monthnum%/%postname%/ while permalink structure for custom post type is /something/blog/%year%/%monthnum%/%something_post%.

    Problem is that when you go to example.com/something/blog/%year%/%monthnum%/ or example.com/something/blog/%year%/, you get archives for posts, not for custom post type. When you go to example.com/something/blog, you are redirected to example.com/blog.

    It also automatically adds permalink structures for feeds, comments

    What you wanted to say with this? Any example?

    BTW, I wanted to report this to your tracker but I can’t login with OpenID, I get 500 Internal Server Error when I’m redirected from my OpenID provider.

    • John P. Bloch · October 21, 2010

      Use %post_type% instead of just something. Plain text means nothing to the rewrite engine. You have to have rewrite tags to insert meaningful data into the structure. Your current permalink (except for single views) is basically telling WordPress to get your posts’ archives because you don’t have %post_type% anchoring the whole structure telling WP to look for that post type.

      There is nothing preventing normal registration on my bug tracker. If OpenID didn’t work, there’s nothing wrong with creating a regular user (which is what OpenID would be doing anyway). The main reason I added OpenID was for my own convenience.

    • John P. Bloch · October 21, 2010

      Also, I apologize for taking so long to reply to you. I don’t know how I missed your comment…

      • Milan · October 21, 2010

        I continued discussion about my problem over at support forums (since I believe it is better to have it over there).

        About OpenID: I use OpenID so that I don’t need to register again, and when I saw it, I started process with it. Since it didn’t work, I was lazy to register usually and instead just reported you issue with OpenID here ;)

  9. Paul Papadimitriou · October 28, 2010

    Hey John,

    thanks for the time and dedication for creating this plugin.

    I’ll admit not fully grasping what it can do as I wasn’t able to make the options appear on the Permalinks settings (I’ve tried altering the permalinks on the WP test install, not to avail.).

    But maybe before going there, let me tell you why I became interested in your plugin. My quest is to be able to deliver category-specific permalinks for a blog. The Advanced Permalink plugin is not supported anymore and doesn’t seem to work with WP 3.0+ (http://urbangiraffe.com/plugins/advanced-permalinks/).

    Do you reckon your plugin would help me achieve a similar result -or is its purpose more about rendering pages into hierarchical entries?

    Sorry if I misunderstood the purpose of the plugin. In any case, thanks for the work and making it available for all of us to use (and, for me, bother you with it ^^).

    Cheers

    • John P. Bloch · November 1, 2010

      Hi Paul,

      If you’re using WordPress’ built in blog posts, my plugin isn’t going to do anything for you. My plugin works specifically for custom post types. WordPress has 5 built in post types: Posts, Pages, Attachments, Revisions, and Navigation Menu Items.

      For CPT’s in WordPress 3.0.x, the default permalinks are extremely basic and inflexible and my plugin allows users to modify this structure.

      -John

      • Paul Papadimitriou · November 2, 2010

        Hi John,

        thank you for taking the time clarifying the situation for me. I do appreciate it.

        Seems the plugin does not what I’m currently looking for, but stays a very potent addition to the wordpress roaster of plugins. Could come handy for me in the future.

        I’ll be sure to talk about it around me, I know some folks will love it.

        Kind regards,

        Paul.

  10. Alessio · November 6, 2010

    thank you for plugin, I have a question, I changed my post_type permalink with this structure: /scheda-tecnica/%scheda-tecnica%.html, but the url of post return 404 not found, old permalink had /scheda-tecnica/%scheda-tecnica%, and now this redirect to url with “.html” and return 404 error … thnak you

  11. Alessio · November 6, 2010

    ops… I use this with Custom Post Types UI plugin

  12. Vikingbanana · December 25, 2010

    If anyone has any insight to this dilema it would be appreciated
    I have a custom post -> listings and when a user adds a listing from there county and city choice in admin I insert the county as a parent category and city as child to county. then I’d like the url for the listings to be
    mysite.com/listings/plumas/chester/listing-name where plumas is a county and chester the city in plumas.
    I tried post_link filter which works in changing the permalink on the admin page but it isn’t accessible form front end , updating permalinks didn;t do anything either.

    I tried this plugin and it added the county but wouldn’t add the city, checking revealed wordpress only takes the lowest id category into the url. SO how can i get that subcat to be in the url always.

    • Vikingbanana · December 26, 2010

      okay so I solved it for this scenario.
      I also should have added the user doesn’t pick from a list of county city categories, I have them enter address and then get county info from google maps and then verify by showing them there adress with county and they have option to overide and then on save I check for existing county city categories and insert if they don’t exist and ten this was hte crucial part only add the listing to the subcategory and ten using this plugin the parent county and city sub show up and save into the permalink and work no 404s.

  13. Li · February 4, 2011

    hi,
    I installed this plugin,
    but i cannot update the permalinks structure for custom posts,
    no matter what I put in the input field, after I save the options the default value reappears..
    so I basically have permalink structure of [post type slug]/[post type = post name]
    Any idea what is wrong?

    • John P. Bloch · February 5, 2011

      What is the code you used to register the post type, what is your default WordPress permalink structure, and what is the permalink structure you’re trying to set? Also, what other plugins are you using and what theme are you using?