If you are a marketer or developer then you have to need to insert various types of code into your WordPress website or blog. So here we will discuss the various methods for How to Add Code in WordPress.
How to Insert Code in WordPress?
There are various conditions for WordPress for adding the code. So we will discuss all the methods?
- Insert any type of custom or tracking code in Header & Footer.
- Add HTML Code in WordPress Posts and Pages.
You can add custom or tracking code by two methods.
- You can add using the plugin.
- Insert Manually in WordPress.
Step 2: You will find the Insert Headers and Footers in Settings in the WordPress Admin Dashboard.
Step 3: If you want to paste the tracking or custom code into the Header of WordPress then put the code into Scripts in Header. This will add your code to the head section of your website.
After putting the code then Save this Code.
If you want to paste the code into the footer of your WordPress website. Paste your tracking or custom code into Scripts in Footer. Save the code.
This is the first method for putting the code into WordPress Headers and Footers.
You should use this method if you do not want to use the plugin for inserting the code.
Step 1: Go to the Appearance section and Click Editor or Theme Editor.
Step 2: On the right side, you will see the Theme Files. Open Header file which is in the form of header.php file.
So put your code into head section between <head></head> tags. After putting your code then save your header.php file.
So your custom or tracking code will be successfully inserted.
If you want to put your custom or tracking code into the WordPress Footer then follow this guide.
Step 1: Go to Appearance, Open Theme Editor.
Step 2: In the Theme Files, Open Footer ( footer.php) file.
Step 3: Put your code before the </body> tag in the footer.php file. Your code will be successfully added. Save the header.php file.
Note: If you want to put your code after <body> tag then the <body> tag will be found in the header.php file.
How to Add HTML Code to WordPress Post & Pages?
If you want to insert HTML code into WordPress Posts & Pages then follow this guide. This will remain the same for posts and pages.
Step 1: If you are using Gutenberg editor then you will see a + ( plus ) sign in the upper side. Click on the Plus sign.
Step 2: After clicking on the plus sign, you will see many options like
- Most Used
- Inline Elements
- Common Blocks
- Layout Elements
- Yoast Structured Data blocks
Click on Formatting for adding the code. In Formatting, you will see Custom HTML. Click on Custom HTML.
When you will click on Custom HTML then you will see an HTML Box like this. Paste your HTML Code into HTML.
Example: We put a code into HTML.
<h5>This is our first headings</h5>
In Preview, it will show the result like this.
So this will successfully insert your HTML Code into WordPress posts and pages like this in Gutenberg.
If you are using Classic Editor and want to paste the HTML Code then follow this guide.
Step 1: Go to Classic Editor and You will see two options.
- Visual Editor
- HTML Editor
Choose HTML Editor. Paste your HTML Code. Paste your code between paragraph tags.
After pasting the code, move on Visual Editor. It will show your HTML result like this.
So you can insert your HTML Code into Classic Editor like this. So this is the complete guide about How to Insert Code into WordPress Posts & Pages.
With the help of this guide, you can easily insert your Custom or HTML Code into WordPress Headers & Footers and Post & Pages easily. You can put
You can apply any of these methods for your WordPress website or blog.
If you have liked this article then please share it and like our Facebook Page.
We love to hear from you about which method do you want to use. Please let us know in the comment section.