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>

      <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>

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.com/home) and site_url('/') (if your home URL is example.com/).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.