如何将徽标链接到自定义网址wordpress

时间:2016-03-10 11:16:59

标签: php html wordpress

我试图让我的徽标链接回到登陆页面。 我曾尝试将我的徽标链接到自定义网址,但我每次都会崩溃网站。

以下是header.php的一个片段,感谢任何帮助。

   <?php
     /***************************************
                SITE LOGO           
    ***************************************/
    if ( !function_exists( 'be_themes_get_header_logo_image' ) ) {
    function be_themes_get_header_logo_image() {
        global $be_themes_data;
        $logo = get_template_directory_uri().'/img/logo.png';
        if( ! empty( $be_themes_data['logo']['url'] ) ) {
            $logo = $be_themes_data['logo']['url'];
        }
        if( ! empty( $be_themes_data['logo_sticky']['url'] ) ) {
            $logo_sticky = $be_themes_data['logo_sticky']['url'];
        } else {
            $logo_sticky = $logo;
        }
        if( ! empty( $be_themes_data['logo_transparent']['url'] )) {
            $logo_transparent = $be_themes_data['logo_transparent']['url'];
        } else {
            $logo_transparent = $logo;
        }
        if( ! empty( $be_themes_data['logo_transparent_light']['url'] )) {
            $logo_transparent_light = $be_themes_data['logo_transparent_light']['url'];
        } else {
            $logo_transparent_light = $logo_transparent;
        }
        echo '<a href="'.home_url().'">';
            $post_id = be_get_page_id();
            if(is_singular( 'post' ) && is_single($post_id) && isset($be_themes_data['single_blog_hero_section_from']) && $be_themes_data['single_blog_hero_section_from'] == 'inherit_option_panel') {
                $header_transparent = $be_themes_data['single_blog_header_transparent'];
            } else if((in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && is_product($post_id)) && isset($be_themes_data['single_shop_hero_section_from']) && $be_themes_data['single_shop_hero_section_from'] == 'inherit_option_panel') {
                $header_transparent = $be_themes_data['single_shop_header_transparent'];
            } else {
                $header_transparent = get_post_meta($post_id, 'be_themes_header_transparent', true);
            }
            if(!empty($header_transparent) && isset($header_transparent) && ('none' != $header_transparent)) {
                echo '<img class="transparent-logo dark-scheme-logo" src="'.$logo_transparent.'" alt="Logo" />';
                echo '<img class="transparent-logo light-scheme-logo" src="'.$logo_transparent_light.'" alt="Logo" />';
                echo '<img class="normal-logo" src="'.$logo.'" alt="Logo" />';
                echo '<img class="sticky-logo" src="'.$logo_sticky.'" alt="Logo" />';
            } else {
                echo '<img class="normal-logo" src="'.$logo.'" alt="Logo" />';
                echo '<img class="sticky-logo" src="'.$logo_sticky.'" alt="Logo" />';
            }
        echo '</a>';
    }
}

1 个答案:

答案 0 :(得分:0)

你没有留下足够的信息,所以我会对你的意图做出一些假设。

看起来这部分只是根据不同的标准获取不同img文件的URL。所以,这部分应该没有改动。

   <?php
     /***************************************
                SITE LOGO           
    ***************************************/
    if ( !function_exists( 'be_themes_get_header_logo_image' ) ) {
    function be_themes_get_header_logo_image() {
        global $be_themes_data;
        $logo = get_template_directory_uri().'/img/logo.png';
        if( ! empty( $be_themes_data['logo']['url'] ) ) {
            $logo = $be_themes_data['logo']['url'];
        }
        if( ! empty( $be_themes_data['logo_sticky']['url'] ) ) {
            $logo_sticky = $be_themes_data['logo_sticky']['url'];
        } else {
            $logo_sticky = $logo;
        }
        if( ! empty( $be_themes_data['logo_transparent']['url'] )) {
            $logo_transparent = $be_themes_data['logo_transparent']['url'];
        } else {
            $logo_transparent = $logo;
        }
        if( ! empty( $be_themes_data['logo_transparent_light']['url'] )) {
            $logo_transparent_light = $be_themes_data['logo_transparent_light']['url'];
        } else {
            $logo_transparent_light = $logo_transparent;
        }

这是在不同情况下使您的任何不同徽标成为链接的部分。所以这就是变化发生的地方。

        echo '<a href="'.home_url().'">';
            $post_id = be_get_page_id();
            if(is_singular( 'post' ) && is_single($post_id) && isset($be_themes_data['single_blog_hero_section_from']) && $be_themes_data['single_blog_hero_section_from'] == 'inherit_option_panel') {
                $header_transparent = $be_themes_data['single_blog_header_transparent'];
            } else if((in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && is_product($post_id)) && isset($be_themes_data['single_shop_hero_section_from']) && $be_themes_data['single_shop_hero_section_from'] == 'inherit_option_panel') {
                $header_transparent = $be_themes_data['single_shop_header_transparent'];
            } else {
                $header_transparent = get_post_meta($post_id, 'be_themes_header_transparent', true);
            }
            if(!empty($header_transparent) && isset($header_transparent) && ('none' != $header_transparent)) {
                echo '<img class="transparent-logo dark-scheme-logo" src="'.$logo_transparent.'" alt="Logo" />';
                echo '<img class="transparent-logo light-scheme-logo" src="'.$logo_transparent_light.'" alt="Logo" />';
                echo '<img class="normal-logo" src="'.$logo.'" alt="Logo" />';
                echo '<img class="sticky-logo" src="'.$logo_sticky.'" alt="Logo" />';
            } else {
                echo '<img class="normal-logo" src="'.$logo.'" alt="Logo" />';
                echo '<img class="sticky-logo" src="'.$logo_sticky.'" alt="Logo" />';
            }
        echo '</a>';

这将是快速,肮脏和未经测试的。我看到两个可能的预期结果。首先,所有图像应链接到其他地方,这将是最简单的。在设置中更改它一般。这与将其硬编码到头文件中的效果相同。

如果你真的想要硬编码,可以通过改变第二部分的第一行来实现。

更改

 echo '<a href="'.home_url().'">';

echo '<a href="http://www.desired-url.com">';

下一个方法是你只想要一个用新url包装的特定img条件和其他的默认行为。这需要进行更多更改。您需要获取一个img集并围绕它包装所需的链接。因此,您必须将字符串编译为 echo ed,然后在结束时回显它。

$logo_link = '';

$original_url_start = '<a href="'.home_url().'">';
$new_url_start = '<a href="http://www.desired-url.com">';
$url_end   = '</a>';

$post_id = be_get_page_id();

if(is_singular( 'post' ) && is_single($post_id) && isset($be_themes_data['single_blog_hero_section_from']) && $be_themes_data['single_blog_hero_section_from'] == 'inherit_option_panel') {
    $header_transparent = $be_themes_data['single_blog_header_transparent'];
} else if((in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && is_product($post_id)) && isset($be_themes_data['single_shop_hero_section_from']) && $be_themes_data['single_shop_hero_section_from'] == 'inherit_option_panel') {
    $header_transparent = $be_themes_data['single_shop_header_transparent'];
} else {
    $header_transparent = get_post_meta($post_id, 'be_themes_header_transparent', true);
}

if(!empty($header_transparent) && isset($header_transparent) && ('none' != $header_transparent)) {
    $img1 = '<img class="transparent-logo dark-scheme-logo" src="'.$logo_transparent.'" alt="Logo" />';
    $img2 = '<img class="transparent-logo light-scheme-logo" src="'.$logo_transparent_light.'" alt="Logo" />';
    $img3 = '<img class="normal-logo" src="'.$logo.'" alt="Logo" />';
    $img4 = '<img class="sticky-logo" src="'.$logo_sticky.'" alt="Logo" />';

    $logo_link = $new_url_start.$img1.$img2.$img3.$img4.$url_end;
} else {
    $img5 = '<img class="normal-logo" src="'.$logo.'" alt="Logo" />';
    $img6 = '<img class="sticky-logo" src="'.$logo_sticky.'" alt="Logo" />';

    $logo_link = $original_url_start.$img5.$img6.$url_end;
}


echo $logo_link;

如果条件与您想要的条件相反,则交换变量$ new_url_start和$ original_url_start。

改变这个:

$logo_link = $new_url_start.$img1.$img2.$img3.$img4.$url_end;

对此:

$logo_link = $original_url_start.$img1.$img2.$img3.$img4.$url_end;

改变这个:

$logo_link = $original_url_start.$img5.$img6.$url_end;

对此:

$logo_link = $new_url_start.$img5.$img6.$url_end;

希望这有帮助。

最佳,