You can only do that if the user is logged in (otherwise there is no “current” user). Depending on what your specific use case is, it would be something like this:
if ( is_user_logged_in() ) {
global $current_user;
$current_user = wp_get_current_user();
// get the username:
$username = $current_user->user_login;
// set up the URL:
$url = home_url( $username );
}
Here’s the documentation on the core WP functions I used above:
Related Posts:
- How to get URL of current page displayed?
- How is WordPress manipulating the posts like there are folders?
- How to use $_GET function WordPress backend
- Create custom permalinks to show Custom Post Type’s relationship?
- WordPress permalink issue
- Allow two posts (from different categories) to have the same slug
- Rewrite rule not working, but only when parameter is text
- WordPress/NGINX not respecting the category URL for new posts
- How do I generate formatted permalinks as specified in backend options?
- Remove /category/ from category (archive) page URLs (without using a plugin)
- How to extract URLs from wordpress taxonomies
- What is the best practice for escaping data URIs?
- how to get permalink structure with php
- How do I get the author’s page url from their ID?
- Dynamic URL to reference custom PHP files
- How to Remove Parents Category Permalink from Posts
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- Put a link to a category round a hard coded A HREF
- Add filename to attachment page url
- Newbie question: no index.php? in my plain wordpress permalink
- wordpress upgrade has broken my permalinks
- Echo URL of large version of Featured Image
- Add prefix to link url
- php script to change slug in post automatically
- Colon is Missing In My Website Url in WordPress
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress every page is 404 not found including admin resources
- How to change redirection route to a php page for making it only accessible by logged-in members?
- Extend PHP regex to cover “srcset” and “style” attributes
- Search Query: how to construct a search string from two select elements?
- Get URL Parameters from referer
- Get the URL of the page from which an ajax request has been launched within ajax callback
- How to check if the current page is at a specified path in the URL?
- How to get post permalink url without a href
- Post’s ID pattern?
- Change product_base programmatically
- Divi change project category slug
- I’m unable to call img path using single quotes in an array?
- Custom post type permalinks do not appear using the link functions
- How to Handle Going Backwards in Navigation When Referrer in PHP/JavaScript won’t work?
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- Remove slugs from custom posts type
- .html end of URl affected to SEO?
- change default RSS feed URL
- Nginx WordPress and another Web app URL structure
- How to use title attributes in sidebar widget?
- Call featured image url
- Creating customized php files in theme folder
- Creating a Category Taxonomy
- Use an anchor link to open an iframe inside a WordPress page
- Adding custom url to readmore link using get_permalink()
- How to set base url for php widget
- Comment_author_url doing nothing
- Insert PHP code in Text
- Modifying WP URL handing code?
- How to deal with a GET variable of ‘name’?
- Permalinks: site.com/post-tite vs site.com/post-id/post-title for SEO and Speed
- Workaround for og:image unsupported webp image type, Yoast SEO?
- Change permalink structure specific category
- understand what code is doing when prepending /blog
- Custom URL for multiple categories hierarchy
- WordPress redirects to localhost
- Unable to display multiple parameters from url by javascript through shortcodes
- 404 on old link after changing post url
- Get nice name of category from slug (remove dashes of category)
- url not using query string no longer working
- Add Link to PHP message
- Current WordPress Page Title as Search Parameter into A Tag
- Permalink doesn’t navigate to post (changes only url)
- How to edit button permalink inside function.php using a child theme?
- How does one make a URL return dynamic JSON with custom Content Type?
- WordPress generates weird permalinks
- How do I stop my form from adding code to current page URL instead of re-directing. Been stuck for days
- image on homepage disappeared due to change of permalink name
- Require advice handling a URL redirect from a Third Party. URL Params need to populate and then forward to payment
- Custom content using in_category
- WordPress add_rewrite_rule
- 403 Forbidden Localhost Wamp Apache Php
- Previewing/Updating some Pages causes “The requested URL was rejected” Error
- changing static link to relative link
- Permalinks and custom PHP application
- How to solve 404 permalink errors on nginx server
- Some links broken after updating WordPress version
- Create a dynamic buddupress tab
- add_rewrite_rule questions
- extract url from a hyperlinked string in PHP [closed]
- Would it be possible to route WordPress Through an MVC Application
- set new link as permalink
- Retrieve first image url from custom post with pagination
- Magento and WordPress URL integration [closed]
- How to remove parent section in an attachment URL in wordpress?
- Get current WordPress page then add #post ID to the end
- custom data in url
- PHP code for link with text
- Masking external links with internal link for member-only
- Add any username as link prefix and show data from that specific user’s profile on wordpress pages – with no login required
- bloginfo url in javascript
- how to goto specific page number including title with permalink
- WordPress 6.1.1 UTF8 Slug Limit Increase
- Create a custom plugin with dynamic child pages listing database records