Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

15 användbara trick för att konfigurera WordPress som du kanske inte känner till

WP-config är en av de mest kraftfulla filerna på din WordPress site, och den spelar en viktig roll för hur WordPress fungerar bakom kulisserna.

Det finns några mycket användbara WordPress konfigurera tricks som de flesta Beginnare inte känner till.

I den här artikeln delar vi med oss av några av de mest användbara tricken för att konfigurera WordPress som hjälper dig att troubleshoota, optimera och säkra din site.

Useful WordPress configuration tricks

Hur använder man dessa WordPress Konfigurera tricks?

WordPress levereras med en kraftfull konfigurationsfil som heter wp-config.php. Den är placerad i rotmappen på varje WordPress site och innehåller viktiga konfigurationsinställningar.

För att lära dig mer, se vår guide om hur du redigerar wp-config.php-filen i WordPress.

Alla de bästa webbhotellen för WordPress kommer med 1-click WordPress-installation, vilket innebär att du aldrig behöver editera wp-config.php-filen under installationen. Detta är den främsta anledningen till att många användare ej känner till kraften i denna fil.

Du kan använda wp-config-filen för att troubleshoota, optimera och säkra din WordPress site.

Filen wp-config.php är ett kraftfullt tool, och ett litet misstag i koden kan göra din website otillgänglig. Du bör bara edit denna fil när det är nödvändigt och alltid göra en komplett WordPress backup innan du gör några ändringar,

Med detta sagt, låt oss ta en titt på några praktiska WordPress konfigurera tricks som du kan använda på din WordPress website.

1. Grundläggande Settings för att konfigurera WordPress

Som standard behöver du bara fylla i inställningarna för databasen under installationen av WordPress. Om du inte har en wp-config.php-fil kommer du att bli ombedd att skapa en genom att fylla i din database-information.

Default WordPress configuration settings

WordPress kommer att försöka att automatiskt save dessa Settings genom att generera en wp-config.php-fil. Om det Misslyckas måste du dock lägga till dem manuellt.

För att göra det måste du ansluta till din website med hjälp av en FTP-klient. När du har anslutit dig måste du byta namn på filen wp-config-sample.php till wp-config.php.

Rename wp-config-sample.php file

Efter det kan du gå vidare och editera den nyskapade wp-config.php-filen. Du måste add to din database information genom att ändra följande rader:

define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');

Glöm inte att save dina ändringar och uploada filen tillbaka till servern.

2. Lägga till säkerhetsnycklar i WordPress

Standardinstallationen av WordPress addar automatiskt säkerhetsnycklar till din konfigurationsfil. Dessa säkerhetsnycklar används för att add to ett extra säkerhetslager till din WordPress login och cookie autentisering.

Du kan alltid återskapa säkerhetsnycklar om du tror att någon kan komma åt din website utan korrekt autentisering. Om du ändrar säkerhetsnycklar kommer alla inloggade användare att loggas ut.

define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

Mer information finns i vår artikel om WordPress säkerhetsnycklar och hur du använder dem.

3. Ändra WordPress tabellprefix

En typisk standard WordPress installation addar ett wp_ prefix till all WordPress Database table namn. Vissa WordPress-säkerhetsexperter anser att en ändring av tabellprefixet kan göra din WordPress-databas säkrare.

För att göra det måste du ändra följande rad i din WordPress-konfiguration.

$table_prefix = 'wp_';

Om du gör detta för en befintlig website måste du också ändra tabellprefixet i din WordPress-databas. För att göra det, se vår artikel om hur du ändrar prefixet i WordPress database.

4. Slå på debug i WordPress

WordPress har en utvald funktion för debug som allow you att se eller dölja WordPress errors när du är i debug-läge. För att aktivera detta måste du lägga till denna regel i din WordPress-konfigurationsfil.

define( 'WP_DEBUG', true );

You can also turn on debugging while dölj the errors on your website and saving them in a log file instead. För att göra det, add följande rader till dina konfigurationsinställningar.

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Detta kommer att skapa en debug.log-fil i wp-content folder på din website och lagra alla debug errors och notices i log-filen.

5. Ändra din site eller WordPress Address

Normalt kan du ställa in dina WordPress- och Site URL:er från Settings ” General page. Men du kanske inte kan göra det om du inte har tillgång till din WordPress-webbplats, ser redirect error eller just har flyttat din site.

I så fall kan du ändra din site och WordPress URL:er via wp-config.php-filen genom att lägga till följande rader:

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

Glöm inte att ersätta example.com med ditt eget domain name.

6. Åsidosätta filbehörigheter

WordPress allow you to åsidosätta filbehörigheter om din server har begränsande behörigheter för alla användarfiler. De flesta användare behöver inte detta, men det finns för dem som behöver det.

define('FS_CHMOD_FILE', 0644);
define('FS_CHMOD_DIR', 0755);

Om du vill veta mer om filbehörigheter kan du läsa vår artikel om hur du fixar error i fil- och folderbehörigheter i WordPress.

7. Changed Post Revision Settings

WordPress har en mycket användbar funktion för revision av inlägg som allow you att ångra ändringar i dina posts och pages genom att återgå till en föregående version eller en autospara.

Du kan inaktivera eller ändra inställningarna för post revision via konfigurationsfilen. Här är olika inställningar för revision av post som du kan använda.

Du kan ändra hur ofta WordPress lagrar en autospara som en revision genom att lägga till följande rad:

define('AUTOSAVE_INTERVAL', 120); // in seconds

Vissa artiklar på din site kan ha dussintals revisioner av poster beroende på hur lång tid det tog att skriva dem. Om du tycker att den här funktionen irriterar dig kan du limit antalet revisioner per post.

define('WP_POST_REVISIONS', 10);

Om du av någon anledning vill inaktivera funktionen för inläggsrevisioner helt och hållet (rekommenderas inte alls), kan du använda följande kod för att inaktivera inläggsrevisioner.

define( 'WP_POST_REVISIONS', false );

8. Changed WordPress Trash Settings

WordPress kommer med en utvald papperskorgsfunktion som anropas Trash. När en användare skickar ett post till papperskorgen lagras det fortfarande på din website under de nästa 30 dagarna som trash. Efter den tiden tar WordPress automatiskt bort dem för alltid.

You can change this behavior by changing the number of days you want to keep the trash.

define( 'EMPTY_TRASH_DAYS', 15 ); // 15 days

Om du inte gillar den här funktionen kan du inaktivera den genom att lägga till funktionen under:

define('EMPTY_TRASH_DAYS', 0 );

Note: Om du använder noll betyder det att dina posts kommer att tas bort permanent. WordPress skulle ej be om bekräftelse när du klickar på Delete Permanently. Ett oavsiktligt click kan kosta you…

Mer information finns i vår artikel om hur du begränsar eller inaktiverar funktionen för automatisk tömning av papperskorgen i WordPress.

9. Lägga till FTP/SSH-konstanter i WordPress-konfigurationen

Som standard tillåter WordPress dig att uppgradera WordPress core, themes och tillägg från adminpanelen. Det finns vissa servrar som kräver en FTP- eller SSH-anslutning varje gång du försöker uppgradera eller installera ett nytt plugin.

WordPress asking for FTP information

Genom att använda koderna kan du ställa in FTP- eller SSH-konstanter och aldrig behöva oroa dig för det igen.

// forces the filesystem method: "direct", "ssh", "ftpext", or "ftpsockets"
define('FS_METHOD', 'ftpext');
// absolute path to root installation directory
define('FTP_BASE', '/path/to/wordpress/');
// absolute path to "wp-content" directory
define('FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/');
// absolute path to "wp-plugins" directory
define('FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/');
// absolute path to your SSH public key
define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub');
// absolute path to your SSH private key
define('FTP_PRIVKEY', '/home/username/.ssh/id_rsa');
// either your FTP or SSH username
define('FTP_USER', 'username');
// password for FTP_USER username
define('FTP_PASS', 'password');
// hostname:port combo for your SSH/FTP server
define('FTP_HOST', 'ftp.example.org:21'); 

Note: Glöm inte att ersätta sökvägen till WordPress och ftp.example.com med din egen FTP-server.

10. Allow Automatic Database Repair

WordPress har en built-in funktion för att automatiskt optimera och reparera WordPress database. Den här funktionen är dock avstängd som standard.

För att aktivera den här funktionen måste du add to följande rad i din WordPress konfigurationsfil.

define('WP_ALLOW_REPAIR', true);

Följer du detta måste du besöka följande URL för att optimera och reparera WordPress database.

http://example.com/wp-admin/maint/repair.php

Glöm inte att ersätta example.com med ditt eget domain name. Du kommer att se en enkel page med alternativen att reparera eller reparera och optimera databasen. Du behöver inte vara inloggad för att komma åt den här page.

Optimize and repair WordPress database

11. Öka PHP:s limit för minne

Några av de vanligaste WordPress error orsakas av att PHP-minnet är uttömt. Du kan öka limiten för PHP-minnet genom wp-config.php-filen. Klistra bara in koden under:

define('WP_MEMORY_LIMIT', '128M');

12. Flytta wp-content Directory

WordPress allow you to move your wp-content directory. Vissa experter tror att det kan bidra till att stärka WordPress säkerhet.

Du måste add to följande kod till din wp-config.php fil:

define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' );
define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');
define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content/plugins' );
define( 'WP_PLUGIN_URL', 'http://example/blog/wp-content/plugins');

Glöm inte att ersätta example.com med ditt eget domain name.

13. Använda Custom User Tables

Som standard sparar WordPress alla uppgifter om användare i tabellerna wp_users och wp_usermeta. Med hjälp av funktionen under kan du ange i vilken tabell du vill att din användarinformation ska lagras.

define('CUSTOM_USER_TABLE', $table_prefix.'my_users');
define('CUSTOM_USER_META_TABLE', $table_prefix.'my_usermeta');

14. Aktivera nätverk för multi-site

Varje WordPress-webbplats har en built-in multisite-funktion som allow you att skapa flera WordPress-webbplatser med hjälp av samma install. För att lära dig mer, se vår kompletta guide om hur du installerar och setupar WordPress multisite network.

Du kan aktivera Multisite-funktionen genom att lägga till följande rad i din WordPress-konfigurationsfil:

define('WP_ALLOW_MULTISITE', true);

15. Säkra din WordPress-konfigurationsfil

Som du ser innehåller filen wp-config.php mycket viktiga Settings för WordPress. Som standard är den placerad i WordPress rotfolder, men du kan flytta den. Den kan flyttas utanför din public_html directory, så att användare inte kan komma åt den. WordPress vet som standard att leta i andra directories om filerna inte finns i WordPress rotmapp.

Du kan också add to följande kod till din .htaccess-fil för att limit åtkomst till denna fil.

# Protect wp-config.php
<Files wp-config.php>
    order allow,deny
    deny from all
</Files>

Vi hoppas att den här artikeln hjälpte dig att lära dig några användbara WordPress konfigurera tricks som du inte kände till. Du kanske också vill se vår megalista med 55+ mest önskade WordPress-tips, tricks och hacks som du kan använda på din site eller våra val av de bästa WordPress-tilläggen för företags webbplatser.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

52 kommentarerLämna ett svar

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Jiří Vaněk says

    Thank you for the great article. I was particularly interested in point 2, as I constantly struggled to understand the function of these security keys. Thanks for the link in the article to additional content, where I was finally able to learn much more about this function and better understand the whole issue. Regarding point 4, is it good to keep the debug log enabled, or should it only be turned on in case of a problem?

    • WPBeginner Support says

      In most cases it is recommended to not have debug mode active unless you are looking for an error on your site. :)

      Administratör

  3. tareq khury says

    hello and thanks for this important post .
    my question is where i must add this codes , in the config.php file
    but in which line exactly .

    regards

    • WPBeginner Support says

      There is no specific line but it is normally best to add the code to the bottom so it is easy to find and remove should you want in the future.

      Administratör

  4. Ali says

    Thanks alot. But i want to know something more detailed about point 9. Where to place this code and more?

  5. Gurjit Singh says

    Thanks for this useful post.
    i was looking for this 10. Allow Automatic Database Repair.
    Thank you very much.

    Thanks and Regards,
    Gurjit Singh

  6. Sunday says

    I rely on your tutorials for my website development. The problems here are that you did not state clearly where these codes will be pasted in the various environments. Looking forward to your response.

  7. Stu Rader says

    Wow really awesome. This helped so much.

    I’m wresting with one thing setting up my own CDN (which the above took care of 98%:).

    I’m trying to exclude a sub-folder on my CDN sub-domain as it’s throwing an access violation.

    I’ve tried a half dozen NGINX CORS directives in a server block .conf with no joy.

    I want to figure out how to use this file in the main domain rather than how it’s written below:

    Access to Font at ’https://cdn.mydomain.com/wp-content/themes/mytheme/includes/lib/assets/fonts/fontawesome/fontawesome-webfont.woff?v=4.7.0’ from origin ’https://mydomain.com’ has been blocked by CORS policy: No ’Access-Control-Allow-Origin’ header is present on the requested resource. Origin ’https://mydomain.com’ is therefore not allowed access.

    Thanks if you can point me to a fix or relevant info you may have !!

    Stu

  8. Hypez says

    They can verufy the information in the wp-config.php if the password or database names correspond and change them if not.

  9. Gopal says

    My WordPress website adds weird numbers as suffix to every page URL. Why is it happening? I changed the permalinks settings to display post names; it didn’t help.

    Could you please guide me?

    Here are a few page urls of my site:

    • Alex says

      I have this ’issue’ – for me its down to backup buddy needing to be run in alternative WP cron mode. The backup buddy FAQ told me to add this:

      define(’ALTERNATE_WP_CRON’, true);

      to my wp_config.php file which now adds random numbers etc to URLs.

      Its this for me as removing it stops it but also stops backup buddy from working correctly.

  10. ugwu victor says

    I use useronline plugin…When am in the useronline dashboard I notice that some users want to access my default css, upload images link with their browser! So am scared may be they want to hack my site! Please any help on how to stop them

  11. Garratt Campton says

    WordPress Error Log –

    How should I do this in a local environment?

    I’m currently using DesktopServer (Xampp lite – Installs sites with .dev extension locally eg. ”mysite.dev”) with SourceTree (Git) – However trying to figure out what the path I should be using to my error log file is proving difficult. Could I use a full URL path such as ”http://mysite.dev/php_error.log” ? or does it need to be the system file path ”C:/Users/Garratt/Documents/mysite.dev/php_error.log” ?

  12. Nathan Pinno says

    Got a question: How do I transfer ownership of a site from one user to another? Like I set it up with my admin account, but I want to have another user be the main admin and do updates and posts. I doubt I can just set them as an admin and myself as a subscriber and be done with it, so what’s the correct route of doing so?

    • WPBeginner Staff says

      Yes that’s one way to do it. A WordPress site can also have multiple administrators.

      If you also want to transfer them the ownership of domain, web hosting, and database then you will have to create a user account for them in your web hosting control panel. After that you can give them the complete control on domain, hosting, and database as well.

      • Nathan Pinno says

        They already have all that, I’m just helping them redevelop their website (cause it’s not a good look right now nor is it easy to update ATM). Found this awesome church theme for them (cause it’s my church’s website I’m working on), and wanted to see how difficult it would be to switch admins. Last time a site of mine had multiple admins, just the first admin (ID #1) could update the plugins, themes, and WP in general.

  13. john says

    After I got rid of the database error, now I dont have any errors but now I have just blank page with no source code ? Please help what to do now. Thnaks

  14. Maganizo says

    I can’t thank you more! You’ve touched on the heart of any online work in a very clear way! You’re great teachers indeed! It can’t be any better than this! Write more!

  15. brad says

    Hey Guys
    Great site, great info just found it. with the secure

    Securing Your WP-Config File
    where is the code that we need? please

    Brad

  16. Bon says

    is there any configuration in wordpress 3.5 so that the uploaded files will use the defined WP_HOME or WP_SITEURL? thanks

  17. Heather Wood says

    Awesome. There is so much stuff about wordpress I didn’t even know. Like the repair database define code. this is one great article. I will have to bookmark this for sure.

  18. yadicemil says

    Thanks for this useful tips.I!m a beginner and I have a wordpress.org web site.
    I have followed your instructions and changed the wp-config file by copying the secure keys grabbed from the web site: https://api.wordpress.org/secret-key/1.1/salt/
    After putting the new config file into the WP-Admin Folder in the server it gives an error ”Parse error: syntax error, unexpected T_VARIABLE….”
    That line is: ”$table_prefix  = ’wp_’;” and it has never been changed.
    How can I correct this error? Thanks.

  19. Tony Cosentino says

    Great information about such an important are as configuration. With all the pharma hacks going on recently the last tip is my favourite. Protecting that damn wp-config file seems to be the key to palace these days.

    Thank you for the effort putting all of this information in one place for us all to benefit.

    kind regards
    Tony

    • Editorial Staff says

      You will never move the .htaccess file anywhere. That file remains in your public_html folder or the folder where WordPress is installed… The code in that file will disallow all access to wp-config.php file from the web.

      You can move the wp-config.php file to the root directory (one above public_html) to add an extra layer of security. One or the other would be fine… doing both is an overkill.

      Administratör

  20. Andrew Nacin says

    For reference, 3.0 does not include more security keys, nor were 2.9 installs any less secure when it came to authentication.

    The first four are keys. The last four are salts. The salts were missing from wp-config.php before 3.0, but we actually added salts a few versions ago. We added them to wp-config.php in 3.0 so we could easily populate them on install, but they are not necessary.

    If salts are not defined (or remain the default, e.g. ”Enter unique phrase here”), then WP simply generates random strings to use as salts and stores those in the database.

    Also, for an error log, you should instead use these constants:


    define( 'WP_DEBUG', true ); // Enables error reporting.
    define( 'WP_DEBUG_DISPLAY', false ); // Hides the errors.
    define( 'WP_DEBUG_LOG', true ); // Logs errors to wp-content/error.log (or use @ini_set('error_log') )

    This has the added benefit of exposing PHP notices, which provide developers warnings about code that could be better or may have errors in it.

  21. Ozh says

    $_ENV{DATABASE_SERVER} ??
    Syntax doesn’t look correct to me ($_ENV[’stuff’] maybe but {stuff} I don’t think so) and I’ve just checked, couldn’t find any host I have access to that has this defined. Definitely not something common.

    Other than this, nice roundup. Note that WP doesn’t look ”in other directories” to find wp-config.php, it just goes one directory up (which is in most case out of the server document root).

  22. Angie Bowen says

    Thanks so much for all of this great info. This is the side of WordPress I need to learn more about so I’m going to use this post as a springboard to really dive in.

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.