functions - WordPress menu link doesn't work properly

admin2025-06-04  3

I am developing custom site. The header links work on home-page but when I go inside shop then the home-link becomes siteurl/shop how to solve this?

<div id="content" class="site-content">
  <nav class="navbar navbar-expand-sm navbar-light bg-light">
    <a class="navbar-brand" href="<?php site_url('home'); ?>">Home</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav ml-auto">
          <li class="nav-item active">
            <a class="nav-link" href="<?php echo site_url('/shop') ?>">Shop</a>
          </li>

I am developing custom site. The header links work on home-page but when I go inside shop then the home-link becomes siteurl/shop how to solve this?

<div id="content" class="site-content">
  <nav class="navbar navbar-expand-sm navbar-light bg-light">
    <a class="navbar-brand" href="<?php site_url('home'); ?>">Home</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav ml-auto">
          <li class="nav-item active">
            <a class="nav-link" href="<?php echo site_url('/shop') ?>">Shop</a>
          </li>
Share Improve this question edited Jan 16, 2019 at 8:06 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Jan 16, 2019 at 5:33 xreonnxreonn 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

I guess you mean this link?

<a class="navbar-brand" href="<?php site_url('home'); ?>">Homee</a>

Then I'm sure it won't work on any other page than home. It's because site_url() function doesn't print anything - it returns its value.

And don't print it either. That means, that the link above is empty ;)

You should change it to this:

<a class="navbar-brand" href="<?php echo site_url('home'); ?>">Homee</a>

PS. Another thing really concerns me in your code. site_url('home') - it should be site_url('/home') (if your home URL is example/home) and site_url('/') (if your home URL is example/).

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749006652a315561.html

最新回复(0)