Forums

Hard coding site URL bad? (6 posts)

  1. orionis23
    Member
    Posted 1 year ago #

    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!

  2. doodlebee
    Member
    Posted 1 year ago #

    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.

  3. orionis23
    Member
    Posted 1 year ago #

    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!

  4. Curtiss Grymala
    Member
    Posted 1 year ago #

    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');
  5. cubecolour
    ɹoʇɐɹǝpoɯ
    Posted 1 year ago #

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

  6. doodlebee
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags