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
- Switch WordPress to non-absolute links? [closed]
- Use a template file for a specific url without creating a page
- Does WordPress keep track of a post’s URL history and provide automatic redirects?
- Change the “page” slug in pagination
- Change the Author Slug from Username to Nickname
- Change author base slug for different roles
- Multiple endpoints to same page
- Change the author slug from nickname to ID
- Custom slug in front of search URL
- Clash of the rewrites
- How to seamlessly redirect between different archive and singular slugs?
- How to add dot(“.”) in post slug
- How to prevent redirection to max 2147483647 for larger values of the page query variable?
- How to change default page slug?
- How to modify author base slug with groups and slug to use nice_nickname?
- Handle category name URL rewrite before different post type slugs
- 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?
- how to add prefix to post url structor only
- Why does wordpress still strip my query var?
- Appending numbers to url do not break the link
- Hijacking the URL for filtering
- WP Login forms action URLs displayed as pretty URLs in browser (ex with Restore Password)
- How to change ?lang=cn into /cn/
- Author url rewrite
- How to Change Author Posts URL
- Passing & Reading URL Parameters with URL re-writing
- 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
- Change default URL of image attachment
- Prevent WordPress from automatically correcting URLs
- Why is there /index.php/ in all my links? How do I remove it?
- Taking a value from PHP_URL_PATH won’t work after WordPress 5.5 update
- Display content according to current URL
- Server (WordPress) redirects files that are not supposed to (using htaccess)
- redirect 301 old url to new url
- Change WordPress comments url / word
- Add a query string to ALL links on site
- Add rewrite rule for rewrite endpoint
- Migrating a page to be an article
- Allow single quote in URLs
- How to get “extended” path info from URL in a plugin
- Multiple Permalinks for Same Post
- How to perform a query at the URL?
- Using Blog Parent Slug on Blog Posts Only
- add_rewrite_rule not working for language specific characters
- Custom URL rewrite to specific page template
- Is there a way to create alias without using htacess, permalinks or delving into code?
- Load a template page based on part of slug in wordpress
- Define orderby in url
- Alias ‘wp-content’ directory to something shorter (framework?)
- WordPress .htaccess – route other URLs to another app
- Allow UTF-8 characters in the user slug part of URL
- Removing “category” from URLs then “add_endpoint()” won’t work…
- Is there a ‘rake routes’ for wordpress?
- open all .docs in word online
- Change author slug and functionality
- How to add custom variable in url without redirect?
- How do I change attachment slug from name to id
- Adding pretty query parameters
- Changing RSS feed URL structure
- Creating a dynamic URL structure
- How to change the main site url on a multisite installation (network)?
- Append a query string to the end of every URL
- add_rewrite_rule fro html to another url not working
- Access files at new location using old file paths
- 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
- Wildcard forward all posts and pages with few exceptions
- Help with Rewrite Rule for Custom Post Type with Query String
- Rewrite URLs – Custom Post Type – Post Slug, Taxonamy Slug
- Translate custom post type and taxonomy slug in URL?
- A clean custom rewrite rule for weekly archives
- Right url for custom post type
- I want to add a new tag to WordPress URL permastruct
- Change pagination url format
- 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?