快速Google search 带我从一个blog post 作者:Konstantin Kovshenin:
global $wp;
$current_url = add_query_arg( $wp->query_string, \'\', home_url( $wp->request ) );
将其与您的原始代码相结合,您就有了此代码(已更新以符合WordPress编码标准):
function show_theme_switch_link_func( $atts ){
global $shown_theme, $status, $wp;
$desktop_switch_link = get_option( \'show_switch_link_for_desktop\' );
$current_url = add_query_arg( $wp->query_string, \'\', home_url( $wp->request ) );
if ( $shown_theme ) {
$return = \'<a rel="external" data-ajax="false" href="\' . add_query_arg( \'am_force_theme_layout\', \'desktop\', $current_url ) . \'" class="am-switch-btn godesktop">\' . get_option( \'desktop_view_theme_link_text\' ) . \'</a>\';
} else {
if ( !empty( $status ) || $desktop_switch_link == \'yes\' ) {
$return = \'<a href="\' . add_query_arg( \'am_force_theme_layout\', \'mobile\', $current_url ) . \'" class="am-switch-btn gomobile">\' . get_option( \'mobile_view_theme_link_text\' ) . \'</a>\';
}
}
return $return;
}