0

I am new to Wordpress. I am converting html site to wordpress site and have added webpage content in the wordpress text editor. Everything is fine, but i have a link in that webpage which redirects to home page, i.e anchor tag with reference to index.html. So after adding that page to wordpress in text editor, i have changed it to "http://localhost/sitename/" which links to home page.

My question is, how to remove localhost and yet link it to homepage. I tried php home_url(); inside anchor tag but didn't work.

I am attaching screenshot enter image description here

4
  • 1
    <a href="/">Home</a>? Commented Oct 17, 2016 at 5:53
  • that will open the directory, i want to link it to homepage(index.html) without using localhost in url Commented Oct 17, 2016 at 6:26
  • Then /sitename/index.html, or just /sitename/, if you have the auto-index feature :) You don't have to write http://localhost explicitly (no need in absolute URLs on your own site). Well, there is get_home_url() function. In a PHP script you can do something like <a href="<?php echo get_home_url(); ?>">Home</a> Commented Oct 17, 2016 at 6:28
  • I got it. And if i change my site's name, i need to change /sitename/index.html in all pages. Is there anything like "/home_page_url/index.html" so that i don't need to change in all pages in case if i change site's name in future. Commented Oct 17, 2016 at 6:36

4 Answers 4

1

You can use home_url PHP function:

<a href="<?php echo home_url(); ?>">Home</a>

You may need to install a widget/plugin to support PHP in WordPress pages. Check out this answer.

Sign up to request clarification or add additional context in comments.

7 Comments

it made the whole anchor tag disappear!
@Nag, is it a PHP script, or static HTML? It can't just disappear. There should be something in the source of the page. If there is nothing, then something should be written to the server logs (if it is a PHP script, again).
it's a static html page
i have attached screenshot..hope it's more clear now
...so only way is, add sitename to the url since its just html page in the. Alright, Thanks for the help
|
0
get_site_url( int $blog_id = null, string $path = '', string $scheme = null )

Retrieves the URL for a given site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.

get_home_url( int $blog_id = null, string $path = '', string|null $scheme = null )

Retrieves the URL for a given site where the front end is accessible.

In your case you can use

<?php echo get_home_url(); ?>

Comments

0

This might help if I am understanding your question:

  1. Login to WordPress admin dashboard
  2. Click on Settings >> General
  3. Fill in your WordPress Address and Site Address and click Save.

5 Comments

my question is very simple,i want to link that webpage to homepage(i.e index.html) without using localhost in url
If you set the URLs in the settings page and then use the home_url() it will use the point to your home page e.g. yourdomainname.com
<a href="/silverspring/">Home</a>
i think there's no solution except giving the sitename
Alryt, Thanks for the help
0

use the broken link checker plugin. which will scan all your links and return to you all the links that are not part of your site()_url then you can just edit the urls, find plugin here or you may go to you php myAdmin and run the following query

UPDATE wp_posts SET post_content = REPLACE(post_content, 'localhost/silverspring/', 'www.yourlivesite.com/');

wp_ will depend of what you have given your tables prefix.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.