WordPress.org

Ready to get started?Download WordPress

Forums

URL Bug/Solution (1 post)

  1. valtido
    Member
    Posted 3 years ago #

    Problem
    I always find it difficult working with websites, especially when working locally-to live.

    The main problem is because we usually save urls e.g. "mywebsite.com/images/logo.jpg" somewhere on database, when we go live, then we have to manually change the urls, and pages and everything.

    Sometimes we even work on sub directories until the website is up and running.

    My solution to this is.

    When we use an insert,update function to enter and update data on db instead of saving urls like.
    "mywebsite.com/images/logo.jpg" the "$wpdb->insert( $table, $data, $format );" should search and replace the "mywebsite.com/" with "{site_url}" and then,

    On "get_result" we reverse it like so "str_replace('{site_url}',get_bloginfo('site_url'),$data);" this way we never save the actual website url on a db at all, except on the configuration table should have an exception there so we can change the site url, take all the files from local, put it live, change url, the website should work fine. I have done this on a previous project myself and it works like a charm will save alot of headaches for people especially web developers or people who create templates of wordpress to save time but find urls a bit difficult to handle.

Topic Closed

This topic has been closed to new replies.

About this Topic