【问题标题】:How to point wordpress website main logo link to another URL?如何将 wordpress 网站主徽标链接指向另一个 URL?
【发布时间】:2021-11-20 04:06:31
【问题描述】:

我正在使用 Flatsome 主题,我希望网站主徽标指向另一个链接而不是主页,有人可以帮我吗?这是我的 header.php

谢谢

<!DOCTYPE html>
<!--[if IE 9 ]> <html <?php language_attributes(); ?> class="ie9 <?php flatsome_html_classes(); ?>"> <![endif]-->
<!--[if IE 8 ]> <html <?php language_attributes(); ?> class="ie8 <?php flatsome_html_classes(); ?>"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html <?php language_attributes(); ?> class="<?php flatsome_html_classes(); ?>"> <!--<![endif]-->
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>" />
    <link rel="profile" href="http://gmpg.org/xfn/11" />
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />

    <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

<?php do_action( 'flatsome_after_body_open' ); ?>
<?php wp_body_open(); ?>

<a class="skip-link screen-reader-text" href="#main"><?php esc_html_e( 'Skip to content', 'flatsome' ); ?></a>

<div id="wrapper">

    <?php do_action( 'flatsome_before_header' ); ?>

    <header id="header" class="header <?php flatsome_header_classes(); ?>">
        <div class="header-wrapper">
            <?php get_template_part( 'template-parts/header/header', 'wrapper' ); ?>
        </div>
    </header>

    <?php do_action( 'flatsome_after_header' ); ?>

    <main id="main" class="<?php flatsome_main_classes(); ?>">

这是我在 'template-parts/header/header 中找到的,所以当我输入我希望它指向主页 url 的链接时,它会将我带到 404 错误页面

<!-- Header logo -->
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?><?php echo get_bloginfo( 'name' ) && get_bloginfo( 'description' ) ? ' - ' : ''; ?><?php bloginfo( 'description' ); ?>" rel="home">
    <?php if(flatsome_option('site_logo')){
      $logo_height = get_theme_mod('header_height',90);
      $logo_width = get_theme_mod('logo_width', 200);
      $site_title = esc_attr( get_bloginfo( 'name', 'display' ) );
      if(get_theme_mod('site_logo_sticky')) echo '<img width="'.$logo_width.'" height="'.$logo_height.'" src="'.get_theme_mod('site_logo_sticky').'" class="header-logo-sticky" alt="'.$site_title.'"/>';
      echo '<img width="'.$logo_width.'" height="'.$logo_height.'" src="'.flatsome_option('site_logo').'" class="header_logo header-logo" alt="'.$site_title.'"/>';
      if(!get_theme_mod('site_logo_dark')) echo '<img  width="'.$logo_width.'" height="'.$logo_height.'" src="'.flatsome_option('site_logo').'" class="header-logo-dark" alt="'.$site_title.'"/>';
      if(get_theme_mod('site_logo_dark')) echo '<img  width="'.$logo_width.'" height="'.$logo_height.'" src="'.get_theme_mod('site_logo_dark').'" class="header-logo-dark" alt="'.$site_title.'"/>';
    } else {
    bloginfo( 'name' );
    }
  ?>
</a>
<?php
if(get_theme_mod('site_logo_slogan')){
    echo '<p class="logo-tagline">'.get_bloginfo('description').'</p>';
}
?>

【问题讨论】:

  • 你看过'template-parts/header/header吗?
  • 这是我找到的,请检查。我刚刚编辑了主帖

标签: javascript php jquery wordpress custom-wordpress-pages


【解决方案1】:

您可以在当前活动主题的 functions.php 文件中添加以下代码,并且不要忘记将“https://YourAnotherWebsite.com”更改为您要指向的 URL。

function mrskt_custom_logo_url ( $mrskt_logo_html ) {

$mrskt_custom_logo_id = get_theme_mod( 'custom_logo' );

// Make sure to replace your updated site URL
$mrskt_new_url = 'https://YourAnotherWebsite.com';

$mrskt_logo_html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
esc_url( $mrskt_new_url ),
wp_get_attachment_image( $mrskt_custom_logo_id, 'full', false, array(
'class' => 'custom-logo',
) )
);
return $mrskt_logo_html;
}

// get_custom_logo: Returns a custom logo, linked to home unless the theme supports removing the link on the home page.
add_filter( 'get_custom_logo', 'mrskt_custom_logo_url' );

【讨论】:

  • 您好,感谢您的回答,我刚刚将代码添加到我的functions.php,但它仍在加载到旧网址。我将 ($mrskt_new_url = 'YourAnotherWebsite.com';) url 更改为新链接但仍然相同.. 猜你错过了什么
猜你喜欢
  • 2012-11-14
  • 2019-02-28
  • 2016-07-20
  • 2020-05-23
  • 2015-01-09
  • 2013-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多