diff --git a/themes/ITStudioMainSite/functions.php b/themes/ITStudioMainSite/functions.php index 770c4ae..9741f64 100644 --- a/themes/ITStudioMainSite/functions.php +++ b/themes/ITStudioMainSite/functions.php @@ -18,6 +18,24 @@ function itstudio_theme_setup() { } add_action('after_setup_theme', 'itstudio_theme_setup'); +function itstudio_open_honor_menu_item_in_new_tab($atts, $item, $args) { + $href = isset($atts['href']) ? (string) $atts['href'] : ''; + $host = wp_parse_url($href, PHP_URL_HOST); + + if ($host !== 'honor.itouc.cn') { + return $atts; + } + + $atts['target'] = '_blank'; + $rel = isset($atts['rel']) ? (string) $atts['rel'] : ''; + $rel_tokens = preg_split('/\s+/', trim($rel), -1, PREG_SPLIT_NO_EMPTY); + $rel_tokens = array_unique(array_merge($rel_tokens, array('noopener', 'noreferrer'))); + $atts['rel'] = implode(' ', $rel_tokens); + + return $atts; +} +add_filter('nav_menu_link_attributes', 'itstudio_open_honor_menu_item_in_new_tab', 10, 3); + function itstudio_get_site_content_defaults() { return array( 'footer_links' => array(