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
- change the blog in the url if you go from a specific page wordpress
- Extend PHP regex to cover “srcset” and “style” attributes
- My php header() function is not working [closed]
- Scrape external webpage for first image and add it to new post
- Search Query: how to construct a search string from two select elements?
- Get URL Parameters from referer
- Need help enqueueing webfonts
- Why is $wp->request empty in WordPress 6.0?
- 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
- get_template_directory_uri() providing wrong path for img
- How to pass a PHP $_GET variable and fetch/output it?
- stripping tags from excerpt in WordPress is not working
- Post’s ID pattern?
- Change product_base programmatically
- Divi change project category slug
- How to allow download url redirection only if user logged in WordPress site?
- 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
- How do i add slugs to a URL, but still redirecting to the same page
- Can’t change website Title on wordpress
- Nginx WordPress and another Web app URL structure
- Search only working on front page (index) , not working on other pages
- How to use title attributes in sidebar widget?
- how to get attached file url for current post?
- how to edit a specific post slug using a php code?
- Call featured image url
- Creating customized php files in theme folder
- Creating a Category Taxonomy
- WordPress theme showing blank page
- How do I include an external PHP file in a subdir WordPress install?
- How to add PHP pagination to wordpress
- 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
- Strip hashtag off permalink with php
- 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
- Can not call .php files after switching to %postname%
- WordPress is removing query variables like page, p from the URL of a custom static page
- Workaround for og:image unsupported webp image type, Yoast SEO?
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- 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
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- 404 on old link after changing post url
- Prepend to all image URLs with PHP, only for mobile devices
- Get nice name of category from slug (remove dashes of category)
- how can i redirect dynamic URL in worpress base on ID in htaccess or wp-config or function.php
- url not using query string no longer working
- One Time Access URL after purchasing subscription
- Custom PHP form needs refresh to load page correctly
- Child-Theme Category View with modified permalinks (%category% removed)
- Add Link to PHP message
- Current WordPress Page Title as Search Parameter into A Tag
- How does Permalink work with the AMP plugin after Removing Parent Permalink Catalog from Posts
- Permalink doesn’t navigate to post (changes only url)
- Post permalink buttons all going to the first post
- Permalink changes after several minutes after saving post
- 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
- Permalink like example.com/taxonomy/post_type/postname
- Meta inserted through wp_insert_post gets messed up
- 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
- Need to Echo A Url path to show on a wordpress page
- What is the proper way to call a function (from functions.php) on a link click?
- I want url from a file in media using title file
- 403 Forbidden Localhost Wamp Apache Php
- Previewing/Updating some Pages causes “The requested URL was rejected” Error
- changing static link to relative link
- redirect 301 with special character like WIX site “#!”