customization - Add button to My Sites dashboard page (multisite)?

admin2025-06-03  4

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 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 );
     }
}

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/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 );
     }
}
Share Improve this question asked Feb 5, 2019 at 12:34 joq3joq3 3813 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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 );
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748941178a315011.html

最新回复(0)