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
- Encode text string being appended as query to URL [closed]
- Is it safe to use $_SERVER[‘REQUEST_URI’]?
- The correct method to pass query vars in AJAX using ajaxurl
- How to check if feed URL was requested?
- What is the best practice for escaping data URIs?
- how to get permalink structure with php
- Facebook Comment Count
- urlencoding of the_title() doesn’t work?
- How do I get the author’s page url from their ID?
- Dynamic URL to reference custom PHP files
- Put a link to a category round a hard coded A HREF
- Add filename to attachment page url
- wordpress upgrade has broken my permalinks
- Featured image fallback link to permalink
- Remove query string specific key value
- Echo URL of large version of Featured Image
- Add prefix to link url
- 200 Rewrite blog post links
- php script to change slug in post automatically
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Colon is Missing In My Website Url in WordPress
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress Persistent connection rule does not work for “posts”
- 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
- My php header() function is not working [closed]
- Why is $wp->request empty in WordPress 6.0?
- get_template_directory_uri() providing wrong path for img
- How to pass a PHP $_GET variable and fetch/output it?
- Divi change project category slug
- How to allow download url redirection only if user logged in WordPress site?
- change default RSS feed URL
- How do i add slugs to a URL, but still redirecting to the same page
- Nginx WordPress and another Web app URL structure
- how to get attached file url for current post?
- how to edit a specific post slug using a php code?
- Creating customized php files in theme folder
- Creating a Category Taxonomy
- WordPress theme showing blank page
- Comment_author_url doing nothing
- Strip hashtag off permalink with php
- Insert PHP code in Text
- 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;’?
- understand what code is doing when prepending /blog
- 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
- how can i redirect dynamic URL in worpress base on ID in htaccess or wp-config or function.php
- Custom PHP form needs refresh to load page correctly
- Child-Theme Category View with modified permalinks (%category% removed)
- Add Link to PHP message
- 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?
- Permalink like example.com/taxonomy/post_type/postname
- Meta inserted through wp_insert_post gets messed up
- Require advice handling a URL redirect from a Third Party. URL Params need to populate and then forward to payment
- Need to Echo A Url path to show on a wordpress page
- I want url from a file in media using title file
- changing static link to relative link
- redirect 301 with special character like WIX site “#!”
- What is the best practice for restricting a section to logged in users?
- Create a dynamic buddupress tab
- Weird slug in archives permalink
- WordPress Rewrite Issue
- Would it be possible to route WordPress Through an MVC Application
- Multiple URL from Custom post name
- Passing multiple variables through url (php)
- Get permalink for a post from inside WordPress and route to a related site
- Make a permalink to the most recent blog post
- Whats wrong with my code? Need To add String to shortcode? [closed]
- Accessing WordPress Functions get_permalink() in Vanilla PHP?
- WPMU – How to echo only one URL
- WordPress add parameters with friendly url structure
- How can I change the URL via add_rewrite_rule()
- bloginfo url in javascript
- how to goto specific page number including title with permalink
- WordPress 6.1.1 UTF8 Slug Limit Increase
- why css file not link?how to create permalink?
- How to automatically flush permalinks?
- Execute wp_after_insert_post after the permalink is customized
- Modify the permalink structure for a specific category
- Remove links to the comments section
- I’ve added SKU to Woocommerce permalinks, but I have small issue
- How to create a dynamic url with post title from one website to another?
- Custom plugin with dynamic child pages listing database records