0

I want to add a new button next to the Visit Site and Dashboard link which is visible under multisites dashboard page /wp-admin/my-sites.php

I have managed as far as adding the button here, and renaming the Visit site. But the problem is that the link will always be the current page and not the multisite network page as the Visit site is. Say I have 2 sites in my network, one called site-1 and the other site-2. The link I have created will always go to https://example.com/site-1/mycustomfolder instead of site-2 like it should.

This is the code I have so far:

add_filter( 'myblogs_blog_actions', 'my_sites_visit_site_target_blank', 10, 2 );
function my_sites_visit_site_target_blank( $actions, $user_blog ) {
     $sites = get_blogs_of_user( get_current_user_id() );
     foreach ( $sites as $site )
        {
                $to_replace = ">" . __( 'Visit' ) . '</a>';
                $to_replace_with = " target='_blank' >" . __( 'Preview 1' ) . '</a> | <a href="'.$site->siteurl.'/customfolder/" target="_blank">Preview 2</a>';
                return str_replace( $to_replace, $to_replace_with, $actions );
     }
}
0

This is the solution:

add_filter( 'myblogs_blog_actions', 'my_sites_visit_site_target_blank', 10, 2 );
function my_sites_visit_site_target_blank( $actions, $user_blog ) {
                $to_replace = ">" . __( 'Visit' ) . '</a>';
                $to_replace_with = " target='_blank' >" . __( 'Preview 1' ) . '</a> | <a href="'. esc_url( get_home_url( $user_blog->userblog_id ) ).'/customfolder/" target="_blank">Preview 2</a>';
                return str_replace( $to_replace, $to_replace_with, $actions );
}
  • Anyone know if it is possible to rearrange the buttons in My Sites? I want to have Dashboard in the beginning. – joq3 Feb 5 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.