Why do all links on my WordPress site show me the homepage?

It looks like you’ve constructed an URL relative to the template PHP you’re rendering, i.e.

  • this code is in wp-content/themes/mycustom/index.php
  • you want to load wp-content/themes/mycustom/admin/dashboard.php
  • => relative URL is admin/dashboard.php?

That’s not correct. URLs are relative to the URL the user is currently on in their browser, which may be /, or /category/post-slug, or /year/month/post-slug, or many more combinations for the same post. The user never knows they’re on template mycustom/index.php. It’s safest to use absolute URLs throughout WordPress for this reason, or relative to the root of the domain at the very least. In this case you probably want

get_template_directory_uri() . '/admin/dashboard.php'

(or get_stylesheet_directory_uri() depending on how you want this to behave for child themes). Possibly run through esc_js() too since you’re emitting this into a JavaScript string, although URLs ought to be save without extra escaping in general especially since you control it.

Why the homepage? I’m guessing that’s what you’ve got set up for 404s.

tech