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 fixar du syntax error i WordPress

Syntaxfel i WordPress kan kännas överväldigande, särskilt om du är nybörjare på kodning.

Du kan stöta på det här problemet när du lägger till kodsnuttar från tutorials. Även ett litet misstag kan förstöra hela din webbplats.

Om du har sett det fruktade meddelandet ”Syntax error, unexpected…” behöver du inte gripas av panik – du har kommit till rätt ställe! Vi har stött på och åtgärdat det här felet många gånger på våra webbplatser, och vi vet hur vi kan hjälpa dig att lösa det.

Den här guiden går igenom stegen för att åtgärda syntaxfelet i WordPress. I slutet kommer du att veta hur du får din webbplats att fungera smidigt igen.

How to Fix the Syntax Error in WordPress

Vad är ett syntaxfel i WordPress och varför ska jag bry mig?

Ett syntaxfel i WordPress uppstår när den kod du har lagt till har felaktig syntax, vilket innebär att den inte följer reglerna för programmeringsspråket.

Den här typen av fel kan bero på något så enkelt som ett saknat kommatecken, en extra parentes eller ett felplacerat citattecken.

Så varför ska du bry dig om syntaxfel?

För det första kan de få hela din webbplats att stanna upp. Istället för att se din vackert utformade webbplats möts besökarna av ett felmeddelande. Detta påverkar inte bara användarupplevelsen utan kan också skada din webbplats rykte och tillförlitlighet.

Dessutom kan syntaxfel göra det omöjligt för dig att komma åt ditt WordPress-adminområde. Detta kan vara särskilt stressande om du är obekväm med kodning och inte vet hur du ska åtgärda problemet.

Kort sagt är syntaxfel små men betydelsefulla misstag i din kod som kan ha stor inverkan på din webbplats. Att kunna identifiera och åtgärda dessa fel snabbt är nyckeln till att upprätthålla en smidig och professionell webbplats.

Använd rätt syntax för att undvika fel

Att se till att din kod är korrekt skriven från början kan spara dig mycket huvudvärk. Genom att vara uppmärksam på korrekt syntax kan du undvika många vanliga fallgropar som leder till fel.

Det första du behöver göra är att titta på nybörjarens guide till att klistra in kodsnuttar från webben i WordPress. I den här artikeln listas några vanliga misstag som nybörjare gör när de klistrar in kod i WordPress-mallar.

Example of a syntax error in WordPress

Syntaxfelet orsakas vanligtvis av ett litet men avgörande misstag i din kodsyntax. Till exempel kan ett saknat kommatecken eller en extra hakparentes förstöra hela skriptet.

Har du nyligen klistrat in ett utdrag från webben? Uppdaterat ett plugin? Då är chansen stor att du vet exakt var du ska leta.

Videohandledning

Subscribe to WPBeginner

Om du föredrar skriftliga instruktioner, fortsätt att läsa.

Åtgärda syntaxfelet med hjälp av FTP

För att åtgärda syntaxfelet måste du redigera koden som orsakade det. Du kan antingen ta bort den eller korrigera syntaxen.

Ofta får nybörjare panik eftersom detta fel gör hela deras webbplats otillgänglig.

Om du klistrade in koden med hjälp av din WordPress-panel i avsnittet Utseende ” Redaktör, är du utestängd. Du kan kolla in vår guide om vad du ska göra om du är utelåst från WordPress-admin.

Så hur redigerar du koden?

Det enda sättet att åtgärda detta är att komma åt den fil du senast redigerade med FTP. För steg-för-steg-instruktioner kan du läsa vår guide om hur du använder FTP.

När du har installerat FTP-programmet ska du ansluta det till din webbplats och gå till den temafil som behöver redigeras. Om du har glömt vilken fil du behöver redigera tittar du bara på felkoden. Felet kommer att berätta exakt vilken fil och rad du behöver redigera.

Du kan antingen ta bort den kod som du senast lade till eller skriva koden med rätt syntax. När du är klar med att ta bort eller redigera koden sparar du filen och laddar upp den till din server.

Efter det kan du besöka din WordPress-webbplats och uppdatera sidan. Du bör se att din webbplats fungerar igen.

Så här förhindrar du syntaxfel i WordPress

För att förhindra att din WordPress-webbplats går sönder igen rekommenderar vi alltid att du lägger till anpassad kod med ett kodsnippets-plugin som WPCode.

WPCode's homepage

WPCode gör det enkelt att lägga till kodsnuttar i WordPress utan att behöva redigera ditt temas functions.php-fil. Den levereras också med smart validering av kodsnuttar för att förhindra fel.

När du lägger till din anpassade kod kommer WPCode automatiskt att upptäcka eventuella fel. Om du håller muspekaren över ett fel visas användbara instruktioner så att du enkelt kan rätta till ditt misstag.

Smart code snippet validation to find code errors

WPCode kommer också omedelbart att avaktivera din anpassade kod när den upptäcker ett syntaxfel.

Med det här insticksprogrammet behöver du aldrig oroa dig för att din webbplats ska gå sönder när du lägger till kodsnuttar.

Error handling in your custom code snippet

Du kan läsa mer i vår guide om hur du enkelt lägger till egen kod i WordPress.

Är din WordPress-webbplats trasig? Få inte panik – vårt Emergency WordPress Support-team kan hjälpa dig. Vår on-demand-tjänst kan snabbt få din webbplats online igen, med minimal driftstoppstid. Inga löpande kontrakt, bara engångslösningar. Schemalägg ett samtal nu!

Vi hoppas att den här artikeln hjälpte dig att åtgärda syntaxfelet i WordPress. Du kanske också vill se vår guide om hur du åtgärdar WordPress-felet Uppdatering misslyckades / Publicering misslyckades eller vår lista över vanliga problem med WordPress blockredigerare och hur du åtgärdar dem.

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

86 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. Roberta says

    This is a frustrating error and your tutorial allowed me to fix it in less than 5 minutes. Thank you so much!

  3. Jamie den Haan says

    Hi,

    Can someone please help me out? I keep getting a ’SyntaxError: JSON Parse error: Unexpected identifier ”Error” when i want to check out on my website. I don’t know what to do and nobody can place an order!!

    Thanks a lot,

    Jamie

  4. Aaron says

    I get ”critical error: could not connect to server” when I enter my server information. So I can’t even get to the point that your video begins at.

  5. Raffy says

    Thank you SO SO much! The bad snippet was invisible inside the Admin page in WordPress, for some reason, but fully visible in the functions.php found in the FTP!!

    You saved my day, thank you very much again!

  6. Kim martin says

    Thank you SO much! 7 days of getting My hosting service(a very large popular one) to try to fix this no luck just trying to upsell me on things I neither want nor need.

    Me thinking okay a whole new website and i found this, I just actually deleted the whole plugin(elementor) Whoo Hoo!

  7. Micah says

    Hello:

    I have run into this error helping someone else out with their website, so I wasn’t using my actual website when I got this error. I’m wondering how I can remove the error when I’m working on someone else’s site? I have their wordpress. org login information, but obviously I’m locked out of everything now. Any guidance would be appreciated.

  8. Tamia says

    Thanks for this tutorial. I had a parsing/syntax problem when editing functions.php in a new website. I was working on the admin page of my WordPress site when I attempted to comment-out a line of code (using instructions by the theme author) but that caused the error. I had copied the functions.php code to TextWrangler, made the alteration, and pasted the whole doc back into the edit window. In ”updating” the page I got the error and was effectively locked out of the site. So I used FTP to upload and overwrite the relevant doc, using a backup I’d made the previous day (thank goodness for those). If it hadn’t been for WP Beginner’s clear instructions here and on the ”What To Do When You Are Locked Out of WordPress Admin (wp-admin)” post, I’d have been tearing my hair out. Thanks!

  9. Tom Delano says

    In trying to log into my page via Filezilla, am I supposed to use my admin account or my WordPress account? I’ve tried both and the password authentication keeps failing. I have my original admin password and it’s worked consistently since I’ve had the website up.

    • WPBeginner Support says

      Hey Tom,

      You’ll need to use your FTP username and password. You will find it in the email you received from your web hosting company when you first signed up. You can also find this information under your cPanel dashboard.

      Administratör

  10. Justine says

    I urgently need help. CO-editor on my site (which is supposed to launch tomorrow) tried to change code to change our profile pictures. Something went horribly wrong and we locked out of our site. Get this error: Parse error: syntax error, unexpected ’add_filter’ (T_STRING) in

  11. Monica says

    Re: my last comment, I deactivated the plugin and the error went away. So you won’t see what I was describing anymore. I just decided to not use it than try to spend all night figuring out the problem.

  12. Monica says

    I am getting parse error syntax errors on all my product pages. This was brought to my attention by someone trying to shop my site. I have not made any edits to the code, installed any new plugins, or accessed the site at all in months. Not sure when this started but I haven’t had an order in few weeks. If I didn’t add or edit anything to cause this how do I know what to fix? All the error messages reference line 1 of the php file but all there is on line 1 is <?php. It's on all product pages. Here is just one example:

  13. shazwan says

    Hi,

    I’m managing a website for my society and its has been long since the last time everyone actually had logged into the hosting account and we kind of lost the log in credentials and didn’t even know what hosting we’re using because they paid years ahead before. And maybe changed providers. But I know that our domain is from Godaddy and checked, but the hosting isn’t from the same provider.

    It may take some time as we dig through the emails, is there any way to fix syntax error other than through FTP?

  14. Patrick says

    Hi. I tried uploading a theme though Filezila since WordPress was having issues trying to upload the theme and now I’m locked up and I get these two lines

    Please Help!!! Thank you!

  15. Francisco says

    Hello,

    I got this error after I updated some plug ins,
    Parse error: syntax error, unexpected ’var’ (T_VAR) in /home/smilesonbristol/public_html/wp-content/plugins/jetpack/sal/class.json-api-date.php on line 55

    Please help.

  16. Spring says

    I cannot thank you enough! You have saved my life! I was to a break point as I thought I’d lost my entire 2 days of work on my new website. Now I have ftp’d the file, and I am back in wp-admin again! Thank you so much for your wonderful site.

  17. sangeet kumar says

    hi

    Parse error: syntax error, unexpected ’define’ (T_STRING) in /home/designba/public_html/wp-content/themes/hestia/functions.php on line 1

    i got the above error message. i cant access any page. i did every steps you mentioned, but i am getting same problem again. actually i didnot change anything in functions.php

    Please Help

  18. Ashley says

    Parse Error: syntax error, unexpected T_FUNCTION in the theme section. I try to fix the error in FileZilla but I’m getting ”Critical error: Could not connect to server”. PLEASE HELP

    • WPBeginner Support says

      Please check your FTP username, password, and host information. You may have received this information in an email when you signed up for your hosting account. You can also ask your hosting support to provide these details.

      Administratör

  19. daphne says

    Here’s another one:
    logged on to the FTP (as suggested by this blog…thanks for that!!), found the files…. but couldn’t download them:
    ….Status: Starting download of /www/wp-admin/theme-editor.php
    Error: Failed to open ”/theme-editor.php” for writing
    Error: File transfer failed…..

    idea? Anyone?

    • Raffy says

      I had the same problem, a red error message when I tried to download it from the right-click window: so I simply searched for my desktop, dragged the file there, edited it, deleted the old functions.php file in my wordpress and dragged the new edited file in the same place. Hope this helps.

  20. Kathleen says

    I am getting this error. I did what you said, pasted in some code that didn’t work. When I took the pasted code out, it still gave me the error. So, fine, I just copied the whole file from a fresh download, and I’m still getting the same error, so I have no idea of what to do now.

  21. Stephen says

    This article saved my life – lol. Thank you so much for the step by step. Fortunately, I had copied and pasted the good code into a text file so going back was easy after I understood what I was looking for.

  22. Tracie says

    OMGosh, thank you for this post! That just happened to me, and I thought I had lost my site for good. What a relief to know the solution was as simple as using FTP.

  23. Walter says

    Hi guys,
    I need some help to solve this issue below quickly please

    ——————————————————-
    Parse error: syntax error, unexpected T_FUNCTION in /home/cardapio/public_html/wp-content/themes/zerif-lite/inc/customizer.php on line 41
    ——————————————————-

    I saw a comment below talking about a video explaining an solution but i didn´t find the link… somebody could help me please?

    • Walter says

      This error happen after I made the plugin´s update by WP Painel.. and now I can´t access the WP Painel anymore… only by FTP

  24. Mikael Andersen says

    Would it be possible for the WP developer team to develop some kind of a script, that is checking out the code syntax in the functions.php file in order to prevent the user from saving the file if it contents any error.

    I think it could be of a big help for many users, especially if a user has taken a copy of the file before making any changes in it.

  25. Imran says

    Hello guys ,

    Can anyone help me with this, I’m having an error when i check my blog health on I dont know how to fix this error. I have tried so hard but couldn’t fix it.

    Improper use of href attribute

    The href attribute specifies the URL of the page the link goes to. Without this attribute, the <a> is not a hyperlink.

    How to solve this issue

    This is essentially a broken link and therefore should be fixed asap so as to not affect SEO negatively.

    Thank you

  26. Samuel Muiruri says

    I’ve got an error Parse error: syntax error, unexpected ’;’ in /home/runningw/public_html/test/wp-content/themes/travel-lite/inc/customize.php on line 167 I was editing customize_register for a theme and on upload on complete it crashed.

  27. Rachel says

    Thank you. This video saved me! Clear information for someone who would not even call themselves a beginner yet! Very much appreciated!

  28. fran garcia says

    Hi.

    I got the same problem, but searching for the theme folder, THERE IS NO FOLDER named like that, so I can’t edit the php!

    Any ideas about how to proceed?

    Thanks.

  29. Raj says

    Parse error: syntax error, unexpected ’:’ in /home/rev/public_html/wp-content/plugins/facebook-pagelike-widget/short_code.php on line 28
    i got above error message cant access my website please help me

  30. Nick says

    It really was a moment to freak out, but thanks to your article it was fixed in a matter of time. Thanks a lot!!

  31. inas dan says

    i have this error in function.php in twenty sixteen chiled theme

    Parse error: syntax error, unexpected ’<' in /home2/hmh49/public_html/myplog/wp-content/themes/twentysixteen-child/functions.php on line 10

    please help

  32. alex says

    It worked beautifully! Thank you!
    I was on a verge of having a shock seeing that my page was not available anymore but thanks to your help I managed to fix the issue! Thank you million!

  33. Kay says

    Hi there,

    I am needing help to fix this error please
    Parse error: syntax error, unexpected ’}’ in /usr/www/users/ogbuldwqdf/wp-content/themes/theme53993/includes/sidebar-init.php on line 51

    I pasted the same code back, but still getting the problem

  34. Sibel Baklacı says

    I have changed my theme’s functions.php file a little bit and now I have an syntax error. Functiıns.php parse error. I can’t access my site anyway. I can’t use ftp to access to it because my site hosted on wordpress.com and they don’t allow using ftp. What I can do to solve this problem. Please help!

  35. zad says

    hi
    i have big problem, help me please :(

    Parse error: syntax error, unexpected ’$content_width’ (T_VARIABLE) in /home/u369283888/public_html/wp-content/themes/mharty/functions.php on line 1

    i used FTP what kan i do to fix it?

  36. Jaideep Bedi says

    I’m stuck in the white screen of death…i did not pasted a code but did a very tiny editing(Appearance->editor) ….it worked and i got what i wanted but later when i tried loading page, it never loaded. On inspecting Element it says: Syntax error Unexpected ” } ” .
    I undo that tiny editing but nothing happend….. please help!!!!
    URGENT

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.