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

Hur man inaktiverar Theme and Plugin Editors från WordPress Adminpanel

Visste du att WordPress levereras med en built-in theme and plugin editor? Denna vanliga kod editor allow you to edit your theme and plugin files directly from the WordPress dashboard.

Det här kanske låter väldigt bra, men det kan också lead till issues som att din site går sönder och potentiella säkerhetsproblem när det kombineras med andra sårbarheter.

I den här artikeln förklarar vi varför och hur du inaktiverar teman och plugins editor från WordPress admin area.

Disable theme and plugin editors in WordPress admin area

Varför inaktivera Theme och Plugin Editors i WordPress?

WordPress levereras med en built-in code editor som allow you att edit WordPress theme och plugin filer direkt från admin area.

Theme Editor finns på sidan Appearance ” Theme File Editor. Som standard kommer den att visa ditt aktiva temas filer.

Theme file editor in WordPress

På samma sätt kan plugin editor ses på Plugins ” Plugin File Editor page. Som standard kommer det att visa dig ett av de installerade tilläggen från din site som kommer upp först i alfabetisk order.

Plugin file editor in WordPress

Om du besöker the theme or plugin editor page för första gången kommer WordPress att varna dig för att använda editorn kan förstöra din website.

Theme editor warning in WordPress

I WordPress 4.9 uppgraderades Theme och Plugin Editors för att skydda användare från att oavsiktligt förstöra sin website. I de flesta fall kommer Editorn att upptäcka ett fatal error och återgå till ändringarna.

Detta är dock inte garanterat och viss kod kan fortfarande slinka igenom och du kommer att förlora åtkomsten till WordPress admin area.

Det största problemet med den built-in file editor är att den ger full tillgång till att add to alla typer av kod till your website.

Om en hacker tar sig in i ditt WordPress admin area kan de använda den built-in Editor för att få tillgång till all din WordPress-data.

Hackare kan också använda den för att distribuera skadlig kod eller starta DDOS-attacker från din WordPress website.

För att förbättra WordPress-säkerheten rekommenderar vi att du helt och hållet tar bort de built-in-fileditors.

Med detta sagt, låt oss se hur man enkelt inaktiverar theme och plugin editors i WordPress.

Så här inaktiverar du Theme and Plugin Editors i WordPress

Det är ganska enkelt att inaktivera editorerna för teman och plugins i WordPress. Men det är obligatoriskt att lägga till kod i WordPress. Om du inte har gjort det tidigare kan du läsa vår guide om hur du klistrar in snippor från webben i WordPress.

Du måste add to den här kodraden till functions.php-filen i ditt theme, ett site-specifikt plugin eller genom att använda ett code snippets plugin.

define( 'DISALLOW_FILE_EDIT', true );

Vi rekommenderar att du använder tillägget WPCode eftersom det är gratis, användarvänligt och inte kommer att förstöra din website om något går fel.

Note: Det finns också en premiumversion av WPCode som kommer med avancerade funktioner som kodrevisioner, automatiska konverteringspixlar, tidsinställda snippor och mer.

Först måste du installera och aktivera det gratis pluginet WPCode. För detaljerade instruktioner, se vår guide om hur du installerar ett plugin för WordPress.

När pluginet är aktiverat går du till Code Sn ippets Add Snippet från din WordPress dashboard. Håll sedan muspekaren över alternativet ”Add Your Custom Code (New Snippet)” och klicka på knappen ”Use snippet”.

Add a new custom code snippet in WPCode

Lägg sedan till en rubrik för ditt snippet och klistra in koden ovan i boxen ”Code Preview”. Du måste också välja ”PHP Snippet” som code type från dropdown-menyn till höger.

Paste code snippet into WPCode

Därefter är det bara att toggla omkopplaren från ”Activate” till ”Inaktiverad” och klicka på knappen ”Save Snippet”.

Activate and save your custom code snippet

Det är all, plugin och tema editors kommer nu att försvinna från themes och plugins menyer i WordPress admin area.

Som ett alternativ kan du också editera din wp-config.php-fil och klistra in koden ovan precis före raden som säger ”That’s all, stop editing! Trevlig publicering”:

Save sedan dina ändringar och upload filen tillbaka till din website.

Om du inte vill editera filerna direkt kan du installera Sucuri WordPress plugin som erbjuder funktionen 1-click hardening.

Korrekt sätt att edit-filer för WordPress Theme och tillägg

Många användare använder faktiskt WordPress tema- och plugin-redigerare för att leta upp koden, lägga till custom CSS eller editera kod i sina barnteman.

Om du bara vill add to custom CSS till your theme, så kan du göra det genom att använda theme customizer som finns under Appearance ” Customize.

Adding custom CSS via theme customizer

För mer detaljer, se vår guide om hur du lägger till custom CSS i WordPress utan att förstöra din site.

Om du vill leta upp koden i ett tillägg kan du göra det genom att använda en FTP-klient.

För bättre filhantering och syntaxmarkering kan du använda en av dessa code editors för att redigera WordPress-filer på din dator.

Sist men ej minst kan du också skapa ett customize WordPress theme utan att skriva någon kod.

Vi hoppas att den här artikeln hjälpte dig att lära dig hur du enkelt inaktiverar theme och plugin editors från WordPress adminpanel. Du kanske också vill se vår ultimata guide till att förbättra WordPress prestanda och hastighet 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

33 kommentarerLämna ett svar

  1. Syed Balkhi

    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

    Thanks for the tutorial. I used the wp-config.php file and it works great. Especially for customer sites, this option seems very good to me, so that they don’t modify the codes of the site and also in terms of security.

    In the end, I chose the wp-config file mainly so that this function could not be simply turned off from the administration, where it didn’t make any sense to me.

    • WPBeginner Support

      Makes sense :)

      Administratör

  3. Bob Putnak

    This wont accomplish anything these days.
    1) Using the CODE SNIPPETS solution, if the hacker has access to the admin panel, they will simply go to the CODE SNIPPETS panel and DISABLE the snippet.

    2) Likewise, if you added it to the wp-config file, I cant see any reason why someone with access to the Admin panel could not simply INSTALL the CODE SNIPPETS plugin, activate it, then set a rule for:

    define( ’DISALLOW_FILE_EDIT’, true );

    Seems to me that if the hacker has access to the admin panel, there is absolutely no solution to this problem.

    If you disagree, please explain why. My login seems 100% sound.

    • WPBeginner Support

      If someone has admin level access to your site then they could look to add a plugin to bypass the issue. There are other user roles that have access to these sections of your site but not the ability to add plugins and this can help protect you from a non-admin who has this level of access from getting into your files.

      Administratör

  4. Robin Hood

    Thanks for sharing this post. Helpful and Informative.

    • WPBeginner Support

      You’re welcome, glad our content could be helpful :)

      Administratör

  5. isabella

    Hello there! I have the opposite problem I need to add a CSS code in the editor BUT the editor disappeared.
    Do you have any suggestions?
    thanks a lot
    cheers

  6. Mike Sawyer

    Thank you for all the tips and helpful advice. This is the go to for me in case I get stuck. Thanks.

  7. Raj

    Unfortunately this isn’t working for me, I have updated the wp-config.php file but the editor option is still there in my wp dashboard, can you suggest me something?

    • Dave

      Hi Raj,

      I had the same issue, but was able to fix it. Not sure if this is your same issue, but I realized that when copy/pasting from an internet post, sometimes the single/double quotation marks (’ ’) or (” ”) may be a curly quote vs. a straight quote. Try deleting the single quotes, and retyping them.

      Hope this helps!

      -Dave

  8. William Marques

    Is it possible disable save option for all? I want show control panel for my clients, but I do not want that they save the changes.

  9. Bella

    A trillion thank you’s!!

    This tiny piece of code has rocked my world!

    How have I not come across you in the past??

    Keep smiling – Bella

  10. Jimit Shah

    hi
    I want to disable paste command ( through mouse and ctr+v)in my php file in theme editor. So that i can write code not copy any code from outside.I want to give access manual code writing . please help me

  11. Raja Dileep Kumar

    define(’DISALLOW_FILE_EDIT’, true); this function will work on themes/functions.php if i paste the code in wordpress

  12. Pramod Kumar

    It works, Thanks.

  13. John McNamara

    Hi there just wondering if anyone found a way to get around this without access as we have paid $1800 for some to set up a Website that is just a theme with out any changes made to it and wants to be paid more to unlock the editor for us
    Please help!!

      • Graham Peckham

        Hi, well I was hacked yesterday by someone who installed MonsterInsights plugin to my web site, BUT, the line of code you suggest was already installed on wp-config.
        So any suggestions for stopping these
        Cheers

  14. Prasath

    define( ’DISALLOW_FILE_EDIT’, true );

    This one disable the editor for complete pages. I need to disable only for home page and for particular user(for Ex: Editor) . Coz I used page builder. My clients are not intrested to look over that..

    Can any one help me ….

  15. Mark Corder

    I can also confirm that this works when the line is added to a Site-Specific Plugin – which you’ll also find the recipe for here on WPBeginner…

    … so Thanks to you folks for all of it!

  16. Melissa

    Hey there! My cheeky developer has done this to me and I need access… is there a way to ”undo” this clever trick without having FTP access?

    I am also a developer and able to edit the files without any issues, but my contracted developer wants to charge me to access the code… so I am hoping I can jump in somehow!

    Mel

    • Al Klein

      Did you contract for ’all deliverables’? If so, have him deliver the FTP password – it’s a deliverable. (It’s a contract, so it can be enforced by a court. You may not be able to sue for specific action, but you can sue for whatever it will cost to have another developer create a new site that’s exactly like the old one [which will probably bankrupt your existing developer – so it will make him prone to turn everything over to you].)

      If you didn’t have ’all deliverables’ included in the contract, or don’t have a signed contract, consider it a cheap legal lesson. (Law school costs a lot more.)

      • Bill

        Great tip.
        Is there a way to disable a specific editor (for example Elementor) for a specific post (page) type while still allowing access to the classic editor?
        I hope this can be done in the child functions file.

  17. Suresh Khanal

    while reading this post I was wondering why would anyone need to hide the editor link in the WordPress Admin because it is only the administrators who gain access to those links and if they do not get permission to do the things the required, what’s the use? anywhere realize that is good with it helpful when you are setting up blogs for you clients. Thanks for the good tips.

  18. Mark Corder

    This is an excellent tip – and it worked fine for me adding the line to the functions.php file in my twentytwelve-child-theme’s folder. I still see options for customizing the theme (header, background, etc.) – but the ”editor” links are now gone. (I had to press CTRL-R to force a page reload to make them disappear.)

    I always try to remove everything from the backend that a client really shouldn’t be messing with, and those plugin & theme editors are just inviting disaster! It’s wonderful to be able to remove them with a single line of code…

    I really appreciate these tips that edit child-theme functions and files to accomplish something rather than just recommending another plugin – though I realize this departs a bit from the ”beginner” stuff.

    And if you haven’t had this request a thousand times already, I’d love to see you folks open a ”WPAdvanced” site for us hard-core folks!

    • Editorial Staff

      Thanks for the feedback Mark. Yes, we have gotten the request for WPAdvanced in the past. For now our focus is to continue to improve WPBeginner (we’re still not there yet).

      -Syed

      Administratör

  19. Gray Ayer

    A problem encountered with this technique is that it also prevents anyone from upgrading the outdated plugins. Any ideas on that, besides disabling the addition to the wp-config file, upgrading, then restoring the hardened security?

    • Editorial Staff

      That’s interesting. We have this code running on our site, and we can do 1-click upgrades.

      Administratör

  20. joanpique

    Hi, thanks for the tip, yes, it works on functions.php file.

    But this code turn me off my theme options page :(…, is there any other code that only hide editors or something to put in the options page for avoid hidding?

    • Renan Santos

      All you have to do is open your wp-config.php file and paste the code!

  21. Devin Walker

    99% of my clients are non-technical

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.