You can easily write your robots.txt file with the help of the Yoast SEO plugin and it is easy.
How To Create And Edit Robots.txt File
Just login to your WordPress and go the Dashboard.
Go to the Yoast settings, you can find this in the left sidebar and it will be named “SEO”
Go to the tools
Select file editor
From here you can edit the Robots.txt file, as well as .htaccess file.
Once the changes are done, just save the file.
In case if there is no robots.txt file, it will show you the option to create a robots.txt file.
The following given steps will not work if your robots.txt file will not be writable or disabled by the WordPress install.
So, in this case, you can create or edit the Robots file on the server.
How To Create Or Edit Robots.txt File From The Server
If you are using a WordPress site, and your site does not contain a physical robots file to the root then, in this case, WordPress will automatically create a virtual robots file.
To replace the virtual Robots.txt file you have to create a new physical Robots file to your server.
To do this just follow these steps
Create a text file with the name of Robots.txt with the help of any text editors.
Now upload the Robots file to your server under the public.html. If you do not have server-based knowledge then you can go to your hosting support and share your problem.
Now you will not face the issue that WordPress is blocking the access to edit the robots.txt file with Yoast.
But if still, you are facing issues to edit the robots file from the Yoast then you can do this directly to your server.