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

Så här stänger du av PHP error i WordPress

Senast frågade en av våra läsare hur man stänger av PHP error i WordPress?

PHP-varningar och notices hjälper utvecklare att debugga issues med sin kod. Det ser dock extremt oprofessionellt ut när de är synliga för alla dina besökare på din website.

I den här artikeln visar vi dig hur du enkelt kan stänga av PHP error i WordPress.

How to turn off PHP errors in WordPress

Varför och när ska du stänga av PHP error i WordPress?

PHP error som du kan se på din WordPress site är vanligtvis varningar och notices. Dessa är eller ej som interna serverfel, syntaxfel eller fatal errors, som hindrar din website från att hämta.

Notices och warnings är den typ av error som inte hindrar WordPress från att hämta din website. Se hur WordPress faktiskt fungerar bakom kulisserna för mer detaljer.

PHP errors in WordPress admin area

Syftet med dessa error är att hjälpa utvecklare att debugga issues med sin kod. Utvecklare av plugins och teman behöver denna information för att kontrollera kompatibilitet och bästa praxis.

Men om du inte utvecklar ett custom theme, plugin eller webbplats, bör dessa error döljas. För om de dyker upp på the front end av din website för alla dina besökare ser det extremt oprofessionellt ut.

WordPress warning errors on homepage

Om du ser ett error som ovan på din WordPress site, då kanske du vill informera respektive theme eller plugin utvecklare. De kan släppa en fix som skulle få error att försvinna. Under tiden kan du också stänga av dessa error.

Låt oss ta en titt på hur du enkelt stänger av PHP error, notices och varningar i WordPress.

Stänga av PHP error i WordPress

För den här delen måste du editera filen wp-config.php.

I din wp-config.php-fil, leta efter följande rad:

define('WP_DEBUG', true);

Det är också möjligt, att denna rad redan är inställd på false. I så fall kommer du att se följande kod:

define('WP_DEBUG', false);

I vilket fall som helst måste du ersätta denna rad med följande kod:

ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);

Glöm inte att save dina ändringar och uploada din wp-config.php-fil till servern.

You can now visit your website to confirm that the PHP errors, notices, and warnings have disappeared from your website.

Aktivera PHP error i WordPress

Om du arbetar med en website på en lokal server eller i ett staging area, kanske du vill aktivera error reporting. I så fall måste du editera din wp-config.php-fil och ersätta koden som du addade tidigare med följande kod:

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

Den här koden kommer att allow WordPress att börja visa PHP error, warnings, and notices igen.

Vi hoppas att den här artikeln hjälpte dig att lära dig hur du stänger av PHP error i WordPress. Du kanske också vill se vår lista över de vanligaste WordPress error och hur man fixar dem, eller våra expertval av de bästa programvarorna för webbdesign.

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

44 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

    I’ve always disabled PHP errors the hard way with a .user.ini file uploaded to the site via FTP. But I didn’t always manage to hide the PHP errors completely, or it caused problems. I did not know that it can be done even more simply using the wp-config file. I tested it on the web and it works fine. Thanks to this, I no longer have to worry about the .user.ini file, which did not always work correctly.

    • WPBeginner Support says

      It would depend on the specific error you’re seeing on your site but you can also check with your hosting provider to ensure they are not overriding what you’re setting.

      Administratör

  3. A Owadud Bhuiyan says

    If I keep the debug true, but false the debug display. Will the error show on website?

    define(’WP_DEBUG’, true);
    define(’WP_DEBUG_DISPLAY’, false);

    • WPBeginner Support says

      The debug display being false would mean that the errors would not be visible on the front-end of your site.

      Administratör

  4. Janet says

    Thank you so much! This fixed my problem in 30 seconds that I have been waiting for my hosting to fix for over 12 hours.

    • WPBeginner Support says

      Glad our guide could help. As a reminder, this hides the error from your site but you would want to try to resolve the root cause of the error you were seeing.

      Administratör

  5. Karan says

    I have already done false in all . But in healthsite status always show WP debugging mode is enabled. please suggest me something

    • WPBeginner Support says

      You likely have it set to true in another section of the code, you likely want to reach out to your hosting provider for them to take a look and assist you.

      Administratör

    • WPBeginner Support says

      You would want to ensure wp_debug isn’t already added in your file somewhere else.

      Administratör

    • WPBeginner Support says

      You may want to check with your hosting provider to see if they have a log set up from their end

      Administratör

  6. Rebecca P says

    I’ve been advised to turn these notices off and was directed to this article to help me with that. However, I do not have the ’wp_debug’ line in my config file. Do I just add it in? And if so whereabouts in the file?
    Thanks!

    • WPBeginner Support says

      You may want to ensure you did not miss it in your current file but, you would place the code at the bottom of the file :)

      Administratör

  7. Gary Guss says

    Clueless newbie! I’ve changed the wp-config.php file and saved it .. Do I have to upload this file to the server to get it to work? How do I do that Using Cpanel File manager.. Not seeing any debug suppression so I guess its somehow not picking up the edited file.. Halp Halp!

    Thanks,

    GG

    • WPBeginner Support says

      If you’re using the file manager your host offers, and directly edited and saved through that without downloading the file then the changes should be active on your site and you would want to check with your host for why the changes may not be getting applied to the file.

      Administratör

  8. genfoch01 says

    ok so i know this is old, but i’m stumped. i am still getting php errors.

    Fatal error: Uncaught Error: Call to undefined function get_header() in /path/to/wordpress/wp-content/themes/mytheme/index.php:5 Stack trace: #0 {main} thrown in /path/to/wordpress/wp-content/themes/mytheme/index.php on line 5

    note that this issue was caught by a pen test and i was asked to suppress the error to avoid full paths being reveled. Any ideas would be helpful

    • WPBeginner Support says

      That is a fatal error for why it is still being displayed, you would want to either change themes or let your theme’s support know about the error to let you know how to fix it.

      Administratör

  9. Mzu says

    I need a solution on wordpress customizer that is not uploading l am stuck for weeks can’t customise any theme

  10. Abdulrahman says

    I faced the same problem after upating woocommerce plugin and the I used your method

    all erroers disappeared, however, I cannot log into the dashboard where it wp-admin shows a blank page

    is there any solution for that

    Thank you

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.