WordPress One Liner to Customize Author Permalink

Code, One Liner, PHP, Snippet, Wordpress 23 December 2008 6 Comments

Several people have asked me recently how to customize the author permalink from being /author/admin to something like /profile/admin. I have created a simple one line piece of code that you can drop in your themes functions.php to achieve this.

add_filter('init', create_function('$a', 'global $wp_rewrite; $wp_rewrite->author_base = "profile"; $wp_rewrite->flush_rules();'));

Drop this into your themes functions.php wrapped in <?php ?> tags off you go. If you want /author/ to become something other than /profile/ replace ‘profile’ in that one liner with the string of your choice.

6 Responses on “WordPress One Liner to Customize Author Permalink”

  1. John says:

    When inserting this string in my functions.php I now always get the following warning when editing author information:

    Warning: Cannot modify header information - headers already sent by (output started at /home/skogsnat/public_html/wp-content/themes/mimbo/functions.php:477) in /home/skogsnat/public_html/wp-includes/pluggable.php on line 850

    Removing the string doesn’t solve anything as the page then can’t find the original author information anymore.

    Any suggestions on what to do?

    Thanks for a good line of code!

    • Matt says:

      Make sure that you wrap that code inside of <?php code here ?>

      • John says:

        I really did. But this happened anyhow. Then when I took the string away WP can’t find author info but I get 404:ed instead. I’m trying to restore this with a backup now. I’m not really a php expert… would need one sometimes though :p

  2. John says:

    It seems like the string is affecting a lot of other *.php files. For instance the feed button for each author stopped to work when the line is active. But when I remove the line I get a feed at http://mywebsite.com/profile/name/feed.

    Is that possible to explain?

  3. John says:

    Solved it now:
    I made the string active again in functions.php and just replaced the term ”profile” with the original ”author”. Saved the file. Opened the file again and removed the string. Now everything seems intact. But in my case this string caused a lot of trouble, maybe because of my theme?

  4. scribu says:

    Triggering flush_rules() on every page load is not a good ideea.

Leave a Reply