Support » Fixing WordPress » Hard coding site URL bad?

  • Howdy all,

    Couldn’t find an answer to a question I have via search (usually can!) so I’m breaking down, ending my time as a lurker and making my first post…

    I’ve got a client who has access to the general settings page of his blog (his admin dashboard is pretty well stripped down otherwise) as he wants to change up his tagline frequently, but he’s already accidentally changed the site url on one occasion. My question is regarding the code added to functions.php to get things back on track…

    update_option('siteurl','http://example.com/blog');
    update_option('home','http://example.com/blog');

    The documentation says to remove the code once up and running again, but I kinda liked how when that code is in place the URL fields on the general settings page are locked.

    Having to edit functions.php for any future site root moves doesn’t seem like a big deal to me… Any reason not to just keep the code in functions.php to keep those particular fields on the general settings page non-editable?

    Thanks for any insight!

Viewing 5 replies - 1 through 5 (of 5 total)
  • I wouldn’t do it because it adds an extra call to the database – I believe every time someone changes a page or clicks a link through the site – to update these options in the database. It’s completely unnecessary and adds extra load to the server.

    If you want it there, I’d comment it out so you don’t have to rewrite it if you must. But I would definitely not just leave it there to run endlessly.

    Thread Starter orionis23

    (@orionis23)

    Good point…. Just the kind of thing I was afraid I hadn’t considered.

    Thanks for the tip, I’ll leave it commented out then!

    You can, however, hardcode the site URL in your wp-config.php file (which, I believe, will disable the form field that you say he changed in the past).

    define('WP_HOME','http://example.com');
    define('WP_SITEURL','http://example.com');
    Moderator cubecolour

    (@numeeja)

    Charge him to fix it this time & I’m sure he won’t break it again.

    yeah! What the both of them said LOL Those are better options 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hard coding site URL bad?’ is closed to new replies.