php – get wordpress username to customize url

In addition to the December 31 ’19 answer, I think this answer combines many of the answers given on this site. But since this website likes reproductions rather than references, I’ll give a possible solution – including today’s question (1 hour ago according to my current screen).

function prefixed_redirect() {
    global $wp;
    if ( home_url( $wp->request ) == 'your_url' )  { // or maybe something more specific.
        require_once TEMPLATEPATH . '/my-specific-template.php';
add_action( 'template_redirect', 'prefixed_redirect' );

I haven’t tested this code, but it is supported by these references: and How to load a new template page according to a particular URL?.

Now in terms of menu addition, I have this example:

function prefixed_nav_menu_item( $items ) {
    $user = wp_get_current_user();
    $link = '<li><a href="' . get_permalink( $user>get( 'slug' ) ) . '">' . $user->get( 'login' ) . '</a></li>';
    $items = $items . $link;

    return $items;
add_filter( 'wp_nav_menu_items', 'prefixed_nav_menu_item' );

This is also not tested, but according to and it should lead you in the right direction Will go

It may be that your specific theme has a predefined function in formatting menu items that you should look into (of which theme template files are a good starting point).

Leave a Comment