简体   繁体   中英

Add custom URL to WordPress Header

I need to add custom urls to header. I edited Header.php and added this code: <?php print "<a href=localhost/URL1>URL1</a>/<a href=localhost/URL2>URL2</a>"; ?> <?php print "<a href=localhost/URL1>URL1</a>/<a href=localhost/URL2>URL2</a>"; ?> but for some reason URL1 and URL2 are not working.... Can someone help me with this problem?

EDIT: Here is header.php code

    <?php

// Exit if accessed directly
if ( !defined('ABSPATH')) exit;

/**
 * Header Template
 *
 *
 * @file           header.php
 * @package        Responsive 
 * @author         Emil Uzelac 
 * @copyright      2003 - 2013 ThemeID
 * @license        license.txt
 * @version        Release: 1.3
 * @filesource     wp-content/themes/responsive/header.php
 * @link           http://codex.wordpress.org/Theme_Development#Document_Head_.28header.php.29
 * @since          available since Release 1.0
 */
?>
<!doctype html>
<!--[if !IE]>      <html class="no-js non-ie" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 7 ]>    <html class="no-js ie7" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 8 ]>    <html class="no-js ie8" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 9 ]>    <html class="no-js ie9" <?php language_attributes(); ?>> <![endif]-->
<!--[if gt IE 9]><!--> <html class="no-js" <?php language_attributes(); ?>> <!--<![endif]-->
<head>

<meta charset="<?php bloginfo('charset'); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title><?php wp_title('&#124;', true, 'right'); ?></title>

<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 responsive_container(); // before container hook ?>
<div id="container" class="hfeed">

    <?php responsive_header(); // before header hook ?>
    <div id="header">

        <?php responsive_header_top(); // before header content hook ?>

        <?php if (has_nav_menu('top-menu', 'responsive')) { ?>
            <?php wp_nav_menu(array(
                    'container'       => '',
                    'fallback_cb'     =>  false,
                    'menu_class'      => 'top-menu',
                    'theme_location'  => 'top-menu')
                    ); 
                ?>
        <?php } ?>

    <?php responsive_in_header(); // header hook ?>

    <?php if ( get_header_image() != '' ) : ?>

        <div id="logo">
    <a href="<?php echo home_url('/'); ?>"><img src="<?php header_image(); ?>" width="<?php if(function_exists('get_custom_header')) { echo get_custom_header() -> width;} else { echo HEADER_IMAGE_WIDTH;} ?>" height="<?php if(function_exists('get_custom_header')) { echo get_custom_header() -> height;} else { echo HEADER_IMAGE_HEIGHT;} ?>" alt="<?php bloginfo('name'); ?>" /></a>
        </div><!-- end of #logo -->

    <?php endif; // header image was removed ?>

    <?php if ( !get_header_image() ) : ?>

        <div id="logo">
            <span class="site-name"><a href="<?php echo home_url('/'); ?>" title="<?php echo esc_attr(get_bloginfo('name', 'display')); ?>" rel="home"><?php bloginfo('name'); ?></a></span>
    <?php echo "<a href='www.google.com'>URL1</a>/<a href='www.google.com'>URL2</a>"?>;
            <span class="site-description"><?php bloginfo('description'); ?></span>
        </div><!-- end of #logo -->  
    <?php endif; // header image was removed (again) ?>

    <?php get_sidebar('top'); ?>
                <?php wp_nav_menu(array(
                    'container'       => 'div',
                        'container_class'   => 'main-nav',
                        'fallback_cb'     =>  'responsive_fallback_menu',
                        'theme_location'  => 'header-menu')
                    ); 
                ?>

            <?php if (has_nav_menu('sub-header-menu', 'responsive')) { ?>
                <?php wp_nav_menu(array(
                    'container'       => '',
                    'menu_class'      => 'sub-header-menu',
                    'theme_location'  => 'sub-header-menu')
                    ); 
                ?>
            <?php } ?>

            <?php responsive_header_bottom(); // after header content hook ?>

    </div><!-- end of #header -->
    <?php responsive_header_end(); // after header container hook ?>

    <?php responsive_wrapper(); // before wrapper container hook ?>
    <div id="wrapper" class="clearfix">
        <?php responsive_wrapper_top(); // before wrapper content hook ?>
        <?php responsive_in_wrapper(); // wrapper hook ?>

Ok here is code od header.php. I added custom URLs but they are not displayed on website.

You have placed the anchor tag for URL1 and URL2 in

if ( !get_header_image() )

which means it would show both the URLs only when there is no header image and if this is correct try placing the code inside

<?php if ( get_header_image() != '' ) : ?>

and also you are using the wrong form of the url you are using

<a href='www.google.com'>URL1</a>

but rather try using complete url which is <a href='http://www.google.com'>URL1</a>

whats not working? does clicking link give 404?

if 404, then, as suggested, change href to a valid uri.

anything added to header.php will show on frontend, so only your href uri can be the issue, as far as the info you have provided for us goes.

Good Luck :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM