Support » Fixing WordPress » Site in subfolder – will hardcoded links have to be edited once its live?

  • Hi All,

    I have been building my site in a subfolder http://www.mysite.com/wp/ and I have hardcoded links in the pages so the client can test out the site. The problem is when I make the site live (by changing the “Site address (URL)” in settings etc…)all the hardcoded links will still have the /wp/ in them.

    This seems like a problem everyone would have who is working on a site in a subfolder and then it goes live.

    I was hoping I could add PHP code to my hardcoded links so it automatically put in the site address that is set in settings. But WP doesn’t seem to like it when I added in this code. The link and all just disappeared.

    <a href="<?php bloginfo('url'); ?>/?page_id=125">LINK ONE</a>

    If someone could let me know if I will have to change all 100 links across the site after its live or is there a way to do it automatically like my example.

    Thanks in advance.

    Anadac

Viewing 4 replies - 1 through 4 (of 4 total)
  • I used code like this all the time…

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

    Note the trailing slash. All of the functions for returning paths in WordPress (so far in my experience) DO NOT have a trailing slash. I see you are doing that but sometimes you also don’t want the slash depending on the path your trying to work with. Just be aware while building paths dynamically. If I have a path problem, I copy the output from the source and try to load it in a new tab directly to figure out what the problem is and then you can tweak your dynamic output to get the appropriate result.

    I do exactly what you are talking about all the time (but even one more step removed starting on a local development server THEN to subdirectory for final production testing before going live). Then when I am done with the site and the client is happy I just use the instructions on this page…

    http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

    And voila the site is “live”.

    The bigger problems I have are with the links inside the database if the site is actually moved, requiring a search and replace of the paths in the database in that case.

    This may or may not be off topic but you should read this article…
    http://justintadlock.com/archives/2010/11/17/how-to-load-files-within-wordpress-themes

    In case you were also having problems with URI’s for image resources and stuff like that.

    Also bloginfo('url'), bloginfo('home'), and bloginfo('siteurl') have been deprecated…
    http://codex.wordpress.org/Function_Reference/get_bloginfo

    Consider using:
    home_url() and site_url() instead.

    Hope that helps. Find your day well.

    Thanks for the detailed reply.

    The code you mention are you pasting it into a page? Because I thought you can’t have php code in a page or a post which out using some sort of plugin…like below:

    http://wordpress.org/extend/plugins/exec-php/

    How are you hard coding links in a page to other pages in your site with out having the subfolder name in the URL and they still work before you do the “Site address (URL)” switch in settings? And work after that?

    I see. I misunderstood what was going on. When you said you tried…

    <a href="<?php bloginfo('url'); ?>/?page_id=125">LINK ONE</a>

    I assumed you meant that you were doing so in the template files in your /theme/my_theme/ directory. Not attempting to do that in the WordPress admin while editing pages/posts.

    You definitely don’t want to put php code in your posts (I wouldn’t even with a plugin without a darn good reason and even then probably not).

    The problem you are describing is exactly the one I have when I move my site from the development server to the production server. Any absolute path in your database (in posts/pages etc…) is going to be broken when you change the site url.

    You will need to search and replace the database to do that. Personally I feel most comfortable doing that by exporting the database via phpmyadmin, searching and replacing the .sql file and then backing up the original database in phpmyadmin, and then replacing the original with the search and replaced version. However, you can search and replace directly through phpmyadmin. I have also heard people discussing plugins that help with just this sort of thing but I have never researched such a thing.

    Just be aware however you do it, to search and replace intelligently. Search for enough of the path string to be sure you are only getting what you want and that you don’t miss anything.

    So if you are searching to replace
    http://somedomain.com/devwordpress/

    with http://somedomain.com/

    Then I would search and replace for …
    somedomain.com/devwordpress/

    And then one more time just a search for…
    devwordpress

    Just to be sure I got them all.

    It sucks to mess up a search and replace like that so I am extra careful taking as many steps necessary to keep it safe.

    If you have any more questions, just ask 😉

    Thanks so much for the detailed response.

    I’m a little scared to mess with the database right now on the clients site. I will test something like that on my own site first. I think will just spend a hour relinking everything.

    Some of the pages with lots of links I will just copy and paste the code into a HTML editor and do my Find and Replace then paste it back into WP.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Site in subfolder – will hardcoded links have to be edited once its live?’ is closed to new replies.