skip to Main Content

I’m setting up a wordpress site and coding in the header.php file of my directory. the code for the links on the navbar are as follows:

<a class="nav-link" href="<?php bloginfo('template_directory'); ?>/page/">Page</a>

But when this is selected, instead of taking the user to the domain that i expect, which is www.mydomain.com/page (which has been the case every other time I have done this approach) it take the user to the following:

“www.mydomain.com/wp-content/themes/mytheme/page”

This is really weird, and I have not experienced it before.

I am editing the code via FTP (FileZilla) and using a custom WordPress theme I built myself. When I ran this on a localhost it worked fine, the issue didn’t occur until I started running it on the server. I am doing this because my client is using DreamHost and they do not have a cPanel or File Editor for the plan we use.

Would anyone have any starting point as to why this is occurring? I will attempt to root out more information and update this with more info as I find it.

2

Answers


  1. Chosen as BEST ANSWER

    I fixed it. I went off of Amila Priyankara's answer so I give them most of the credit here.

    Instead of

    <?php site_url( '/store/', 'https' );?>

    Like they suggested, i used

    <?php echo get_site_url('www.mydomain.com', '/store/', 'https' );?>

    Thanks to the research at the link below. This is because we have to display the link using echo, and the <?php get_template_directory(); ?>was returning the full template directory, rather than just the site url.

    I'm still not quite sure why this has never caused me problems before, but this is good to know that this is another way to solve it.

    https://developer.wordpress.org/reference/functions/get_site_url/


Please signup or login to give your own answer.
Back To Top
Search