How to make a link with subsite?

Hi, I am setting up a blog net work with New Blog Template.

My questions is when a new subsite is created with New Blog Template, I would like to make some links to according to subsite url.

For example,

If a profile page of the main site is http://www.mysite.com/my-profile ,
when a subsite (username / URL is "red" ) is created, the subsite also generate the link like http://www.mysite.com/red/my-profile

I assume you do this with some php code in url like p=1223? or something, but I have no idea.

Could you give me an advice?

Thank you.

  • Vinod Dalvi

    Hi Yosuke,

    I hope you are well today and thank you for your question.

    If a profile page of the main site is http://www.mysite.com/my-profile ,
    when a subsite (username / URL is "red" ) is created, the subsite also generate the link like http://www.mysite.com/red/my-profile

    Are you referring the main site as main site of network or the site which is used to create Blog Template?

    If you are referring it as the site which is used to create Blog Template then the site URL is automatically replaced with the new site URL created using the blog template.

    Please advise.

    Kind Regards,
    Vinod Dalvi

  • Vinod Dalvi

    Hi Yosuke,

    Here are the following some facts about using New Blog Templates.

    You cannot use your main site as a template blog but the subsite.

    The site you’ve customized to use as a template is designed solely to be used as a template and not to be used a functioning site.

    Any changes made to a template blog affect any sites created after you’ve made the new changes, it doesn’t affect sites already created.

    You will find more information about it on the following page.

    https://premium.wpmudev.org/project/new-blog-template/#usage

    So let's get to the point, I am still not clear what you are referring as main site in your initial question so please make it clear and also provide a bit more detail about what you are trying to achieve by sharing real URLs of your site.

    Regards,
    Vinod Dalvi

  • Yosuke

    Hello Vinod,

    I understand that whatever the subsites already made stay as they are.(they don't sync with the template blog site)

    Please take a look the screenshot.
    When subsite was generated, a user account is also created, and the top menu bar as well.

    What I am trying to achieve to change these menu according to their subsite url. Right now, they all points the master site(fixed url) but is there any way to make them dynamic?
    for example, the master site is http://www.mysite.com/my-profile. but if I make a site and user called "red," under the subsite, the same page should be http://www.mysite.com/red/my-profile.

    The reason I am asking to do is I am trying to set up event+ plugin for different paypal account. And I need to make a network to achieve this, so I made subsite and a profile update page (gravity form) to fill in paypal account information. but when I enter paypal account information at http://www.mysite.com/my-profile under the right user. It doesn't reflect actual setting on event+. so I assume that because the site is trying to submitting information to the main site.

  • Ash

    Hello @Yosuke

    I hope you are well today.

    Please try the following code:

    add_action( 'admin_bar_menu', 'toolbar_link_to_my_profile', 999 );
    
    function toolbar_link_to_my_profile( $wp_admin_bar ) {
        $user_info = get_userdata( get_current_user_id() );
        $blog = get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin';
    	$args = array(
    		'id'    => 'my_profile',
    		'title' => 'My Profile',
    		'href'  => $blog . 'wp-admin/profile.php',
    		'meta'  => array( 'class' => 'my-profile-page' )
    	);
    	$wp_admin_bar->add_node( $args );
    }

    With this case, the My Profile menu will always be linked to the logged in user's primary blog profile page.

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.