You can use the %author%
tag in the rewrite
property in register_post_type()
. However, although the rewrite rules are added (after they’re flushed) – WordPress doesn’t replace the tag with its appropriate value when generating the permalink of your post type. For instance you end up with the permalink www.example.com/%author%/gallery-name
The following replaces %author%
with the appropriate value:
add_filter('post_type_link', 'wpse73228_author_tag',10,4);
function wpse73228_author_tag($post_link, $post, $leavename, $sample){
if( 'gallery' != get_post_type($post) )
return $post_link;
$authordata = get_userdata($post->post_author);
$author = $authordata->user_nicename;
$post_link = str_replace('%author%', $author, $post_link);
return $post_link;
}
Related Posts:
- How to change the Author Slug from Username to Nickname and deal with Special Characters
- Override default url for author pages?
- Using custom/dynamic “slug” for a page
- custom htaccess rewrite rule for page
- Adding more pages to author pages
- How to check current URL for endpoint in a template file?
- Adding special characters to slug?
- Preserve old website URL structure after migrating to WordPress
- Make the home page’s slug visible in the browser’s URL bar
- WordPress is adding “category” word before my actual category name in url (and this is unsolicited)
- Change author base and slug in author link
- taxonomy term in URL slug won’t forward to the correct term for custom post like it does for default categories/normal posts
- Remove Page Slug from URL
- Does WordPress keep track of a post’s URL history and provide automatic redirects?
- Change author base slug for different roles
- Change the author slug from nickname to ID
- Custom slug in front of search URL
- Clash of the rewrites
- How to add dot(“.”) in post slug
- How to change default page slug?
- Will references to ugly links automatically redirect to their pretty url permalink?
- How to create a specific frontend URL (not a Page) from a theme or plugin?
- Appending numbers to url do not break the link
- Hijacking the URL for filtering
- How to change ?lang=cn into /cn/
- Author url rewrite
- How to Change Author Posts URL
- Tricky URL rewrite with custom values in url
- How to change page URLs to “www.site.com/page” instead of “example.com/blog/page” but keep post URLs as “example.com/blog/post”?
- Add_query_arg + two times the same argument?
- WordPress 404 unless there is a space in url
- redirect 301 old url to new url
- Add a query string to ALL links on site
- Add rewrite rule for rewrite endpoint
- Migrating a page to be an article
- How to get “extended” path info from URL in a plugin
- Multiple Permalinks for Same Post
- How to perform a query at the URL?
- Is there a way to create alias without using htacess, permalinks or delving into code?
- Define orderby in url
- Removing “category” from URLs then “add_endpoint()” won’t work…
- Is there a ‘rake routes’ for wordpress?
- How do I change attachment slug from name to id
- Changing RSS feed URL structure
- Creating a dynamic URL structure
- add_rewrite_rule fro html to another url not working
- Preserve Domain Alias
- WordPress redirects non-existing url to existing ones – how to disable
- How to rewrite url wordpress?
- How to disable URL rewriting for specific URLs?
- How to building pretty URLs to reflect category hierarchy?
- How to create a profile page for specfic / custom user role members?
- How to create rewrite endpoints it in author.php?
- How do I display only the parent page in the url
- Rewrite custom post type URL parameters
- A clean custom rewrite rule for weekly archives
- I want to add a new tag to WordPress URL permastruct
- Add language prefix to permalinks
- Why is WordPress rewriting absolute URLs on staging site to include staging prefix when we manually point them at the live site?
- React Router with WordPress
- Per Page Permalink Structure for Page Post Type
- How to change custom post type slug
- Rewrite /category/cars into /topics/cars
- URL renaming issue
- Removing “www” from a site URL
- Adding a query string to only one page url
- Bulk append URL (add word to slug)
- One off rewrite for single post-type slug (show normal page with same URL instead)
- Weird characters behind every single link and images
- How to use wp rewrite to hide form action url?
- Can’t use a specific custom URL (slug)?
- How do I get posts to appear at mydomain.com/blog?
- remove archive from url :: marketpress
- Trying to add array of paths to post permalink
- add_rewrite_rule with optional parameters
- How to change search page url so that it still returns a page when there’s no search query specified?
- Append a parametter at first or last to a certain URL
- Allowing multiple URLs for same Post
- How to create dynamic URLs on WordPress?
- Dynamic URL with rewrite rule not working
- Multiple permalink with and without category for same post
- Passing a variable to hyperlink text?
- Param causing 404
- Root-relative paths being rewritten on ‘Edit Page’ [closed]
- rename author base from author url in wordpress not working
- How to add 2 variable rewrite rule?
- Get custom posts by segment of the URL
- Get parameters and custom page template
- Direct Dynamic URL in root to a location within template
- Use Parent Pages for URL Structure without Landing Page
- Needed to change slug to access page
- How to create short urls for sharing and downloadable content?
- How to stop WordPress creating URLs that don’t exist
- Rename page URL
- Listing Authors – URL Formats [duplicate]
- How to exclude my home page from url of my internal pages?
- Lost WordPress website access after changing URL [closed]
- Remove url parameter using wordpress
- Spurious URL structure (Adding extra /0/s)
- WordPress is adding pagination for all pages like www.example.com/page/123. How to remove that?