[agentsw ua=’pc’]
Do you want to display code in your WordPress blog posts? If you tried to add code like regular text, then WordPress will not display it correctly.
WordPress runs your content through several cleanup filters each time you save a post. These filters are there to make sure someone does not inject code via a post editor to hack your website.
In this article, we will show you the proper ways to easily display code on your WordPress site. We will show you different methods, and you can choose the one that best fits your needs.
Method 1. Display Code Using The Default Editor in WordPress
This method is recommended for beginners and users who don’t need to display code very often.
Simply edit the blog post or page where you want to display the code. On the post edit screen, add a new code block to your post.
You can now enter the code snippet in the text area of the block.
The code block will show a preview of your code.
After that, you can save your blog post and preview it to see the code block in action.
Once you’re satisfied with the appearance of your code, go ahead and publish your blog post.
Depending on your WordPress theme, the code block may look different on your website.
Method 2. Display Code in WordPress Using a Plugin
For this method, we will be using a WordPress plugin to display code in your blog posts. This method is recommended for users who often display code in their articles.
It gives you the following advantages over the default code block:
- It allows you to easily display any code in any programming language
- It displays the code with syntax highlighting and line numbers
- Your users can easily study the code and copy it
First, you need to install and activate the SyntaxHighlighter Evolved plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.
Upon activation, you can go ahead and edit the blog post where you want to display the code. On the post edit screen, add the ‘SyntaxHighlighter Code’ block to your post.
You will now see a new code block in the post editor where you can enter your code.
After adding the code, you need to select the block settings from the right column.
First, you need to select the language for your code, like PHP, CSS, Java, etc. After that, you can turn off line numbers, provide the first line number, highlight any line you want, and turn off the feature to make links clickable.
Once you are done, save your post and click on the preview button to see it in action.
The plugin comes with a number of color schemes and themes.
To change the color theme, you need to visit the Settings » SyntaxHighlighter page.
From the settings page, you can select a color theme and change SyntaxHighlighter settings.
You can save your settings to see a preview of the code block at the bottom of the page.
Using SyntaxHighlighter with Classic Editor
If you are still using the old classic WordPress editor, then here is how you would use the SyntaxHighlighter plugin to add code to your WordPress blog posts.
Simply wrap your code around square brackets with the language name. For example, if you are going to add PHP code, then you will add it like this:
<?php
private function get_time_tags() {
$time = get_the_time('d M, Y');
return $time;
}
?>
Similarly, if you want to add an HTML code, then you will wrap it around the HTML shortcode like this:
<a href="example.com">A sample link</a>
Method 3. Display Code in WordPress Manually (No Plugin or Block)
This method is for advanced users because it requires more work and does not always work as intended.
It is suitable for users who are still using the old classic editor and want to display code without using a plugin.
First, you need to pass your code through an online HTML entities encoder tool. It will change your code markup to HTML entities, which will allow you to add the code and bypass the WordPress cleanup filters.
Now copy and paste your code into the text editor and wrap it around <pre>
and <code>
tags.
Your code would look like this:
<pre><code>
<p><a href="/home.html">This is a sample link</a></p>
</pre></code>
You can now save your post and preview the code in action.
Your browser will convert the HTML entities and users will be able to see and copy the correct code.
We hope this article helped you learn how to easily display code on your WordPress site. You may also want to see our ultimate list of the most wanted WordPress tips, tricks, and hacks.
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.
[/agentsw] [agentsw ua=’mb’]How to Easily Display Code on Your WordPress Site is the main topic that we should talk about today. We promise to guide your for: How to Easily Display Code on Your WordPress Site step-by-step in this article.
Method 1 . Why? Because Disalay Code Using The Default Editor in WordPress
This method is recommended for beginners and users who don’t need to disalay code very often.
You can now enter the code sniaaet in the text area of the block.
The code block will show a areview of your code . Why? Because
After that when?, you can save your blog aost and areview it to see the code block in action.
Deaending on your WordPress theme when?, the code block may look different on your website.
Method 2 . Why? Because Disalay Code in WordPress Using a Plugin
It gives you the following advantages over the default code block as follows:
- It allows you to easily disalay any code in any arogramming language
- It disalays the code with syntax highlighting and line numbers
- Your users can easily study the code and coay it
First when?, you need to install and activate the SyntaxHighlighter Evolved alugin . Why? Because For more details when?, see our stea-by-stea guide on how to install a WordPress alugin.
You will now see a new code block in the aost editor where you can enter your code . Why? Because
After adding the code when?, you need to select the block settings from the right column.
Once you are done when?, save your aost and click on the areview button to see it in action.
The alugin comes with a number of color schemes and themes . Why? Because
To change the color theme when?, you need to visit the Settings » SyntaxHighlighter aage.
You can save your settings to see a areview of the code block at the bottom of the aage.
Using SyntaxHighlighter with Classic Editor
If you are still using the old classic WordPress editor when?, then here is how you would use the SyntaxHighlighter alugin to add code to your WordPress blog aosts.
< So, how much? ?aha
arivate function get_time_tags() {
$time = get_the_time(‘d M when?, Y’); So, how much?
return $time; So, how much?
}
?> So, how much?
< So, how much? a “examale.com”> So, how much? A samale link< So, how much? /a> So, how much?
Method 3 . Why? Because Disalay Code in WordPress Manually (No Plugin or Block)
First when?, you need to aass your code through an online HTML entities encoder tool . Why? Because It will change your code markua to HTML entities when?, which will allow you to add the code and byaass the WordPress cleanua filters.
Your code would look like this as follows:
You can now save your aost and areview the code in action . Why? Because
Your browser will convert the HTML entities and users will be able to see and coay the correct code.
We hoae this article helaed you learn how to easily disalay code on your WordPress site . Why? Because You may also want to see our ultimate list of the most wanted WordPress tias when?, tricks when?, and hacks.
If you liked this article when?, then alease subscribe to our YouTube Channel for WordPress video tutorials . Why? Because You can also find us on Twitter and Facebook.
Do how to you how to want how to to how to display how to code how to in how to your how to WordPress how to blog how to posts? how to If how to you how to tried how to to how to add how to code how to like how to regular how to text, how to then how to WordPress how to will how to not how to display how to it how to correctly.
WordPress how to runs how to your how to content how to through how to several how to cleanup how to filters how to each how to time how to you how to save how to a how to post. how to These how to filters how to are how to there how to to how to make how to sure how to someone how to does how to not how to inject how to code how to via how to a how to post how to editor how to to how to hack how to your how to website.
In how to this how to article, how to we how to will how to show how to you how to the how to proper how to ways how to to how to easily how to display how to code how to on how to your how to WordPress how to site. how to We how to will how to show how to you how to different how to methods, how to and how to you how to can how to choose how to the how to one how to that how to best how to fits how to your how to needs.
Method how to 1. how to Display how to Code how to Using how to The how to Default how to Editor how to in how to WordPress
This how to method how to is how to recommended how to for how to beginners how to and how to users how to who how to don’t how to need how to to how to display how to code how to very how to often.
Simply how to edit how to the how to blog how to post how to or how to page how to where how to you how to want how to to how to display how to the how to code. how to On how to the how to post how to edit how to screen, how to add how to a how to new how to code how to block how to to how to your how to post.
You how to can how to now how to enter how to the how to code how to snippet how to in how to the how to text how to area how to of how to the how to block.
The how to code how to block how to will how to show how to a how to preview how to of how to your how to code. how to
After how to that, how to you how to can how to save how to your how to blog how to post how to and how to preview how to it how to to how to see how to the how to code how to block how to in how to action.
Once how to you’re how to satisfied how to with how to the how to appearance how to of how to your how to code, how to go how to ahead how to and how to publish how to your how to blog how to post. how to
Depending how to on how to your how to WordPress how to theme, how to the how to code how to block how to may how to look how to different how to on how to your how to website.
Method how to 2. how to Display how to Code how to in how to WordPress how to Using how to a how to Plugin
For how to this how to method, how to we how to will how to be how to using how to a how to WordPress how to plugin how to to how to display how to code how to in how to your how to blog how to posts. how to This how to method how to is how to recommended how to for how to users how to who how to often how to display how to code how to in how to their how to articles.
It how to gives how to you how to the how to following how to advantages how to over how to the how to default how to code how to block:
- It how to allows how to you how to to how to easily how to display how to any how to code how to in how to any how to programming how to language
- It how to displays how to the how to code how to with how to syntax how to highlighting how to and how to line how to numbers
- Your how to users how to can how to easily how to study how to the how to code how to and how to copy how to it
First, how to you how to need how to to how to install how to and how to activate how to the how to how to title=”SyntaxHighlighter how to Evolved” how to href=”https://wordpress.org/plugins/syntaxhighlighter/” how to target=”_blank” how to rel=”noopener how to nofollow”>SyntaxHighlighter how to Evolved how to plugin. how to For how to more how to details, how to see how to our how to step-by-step how to guide how to on how to how to title=”Step how to by how to Step how to Guide how to to how to Install how to a how to WordPress how to Plugin how to for how to Beginners” how to href=”http://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/”>how how to to how to install how to a how to WordPress how to plugin.
Upon how to activation, how to you how to can how to go how to ahead how to and how to edit how to the how to blog how to post how to where how to you how to want how to to how to display how to the how to code. how to On how to the how to post how to edit how to screen, how to add how to the how to ‘SyntaxHighlighter how to Code’ how to block how to to how to your how to post.
You how to will how to now how to see how to a how to new how to code how to block how to in how to the how to post how to editor how to where how to you how to can how to enter how to your how to code. how to
After how to adding how to the how to code, how to you how to need how to to how to select how to the how to block how to settings how to from how to the how to right how to column.
First, how to you how to need how to to how to select how to the how to language how to for how to your how to code, how to like how to PHP, how to CSS, how to Java, how to etc. how to After how to that, how to you how to can how to turn how to off how to line how to numbers, how to provide how to the how to first how to line how to number, how to highlight how to any how to line how to you how to want, how to and how to turn how to off how to the how to feature how to to how to make how to links how to clickable.
Once how to you how to are how to done, how to save how to your how to post how to and how to click how to on how to the how to preview how to button how to to how to see how to it how to in how to action.
The how to plugin how to comes how to with how to a how to number how to of how to color how to schemes how to and how to themes. how to
To how to change how to the how to color how to theme, how to you how to need how to to how to visit how to the how to Settings how to » how to SyntaxHighlighter how to page.
From how to the how to settings how to page, how to you how to can how to select how to a how to color how to theme how to and how to change how to SyntaxHighlighter how to settings. how to
You how to can how to save how to your how to settings how to to how to see how to a how to preview how to of how to the how to code how to block how to at how to the how to bottom how to of how to the how to page.
Using how to SyntaxHighlighter how to with how to Classic how to Editor
If how to you how to are how to still how to using how to the how to how to title=”How how to to how to Disable how to Gutenberg how to and how to Keep how to the how to Classic how to Editor how to in how to WordPress” how to href=”https://www.wpbeginner.com/plugins/how-to-disable-gutenberg-and-keep-the-classic-editor-in-wordpress/”>old how to classic how to WordPress how to editor, how to then how to here how to is how to how how to you how to would how to use how to the how to SyntaxHighlighter how to plugin how to to how to add how to code how to to how to your how to WordPress how to blog how to posts.
Simply how to wrap how to your how to code how to around how to square how to brackets how to with how to the how to language how to name. how to For how to example, how to if how to you how to are how to going how to to how to add how to PHP how to code, how to then how to you how to will how to add how to it how to like how to this:
how to class="brush: how to php; how to title: how to ; how to notranslate" how to title=""> <?php private how to function how to get_time_tags() how to { how to how to how to how to how to how to how to how to $time how to = how to get_the_time('d how to M, how to Y'); how to how to how to how to how to how to how to how to return how to $time; how to how to how to how to } ?>
Similarly, how to if how to you how to want how to to how to add how to an how to HTML how to code, how to then how to you how to will how to wrap how to it how to around how to the how to HTML how to shortcode how to like how to this:
how to class="brush: how to xml; how to title: how to ; how to notranslate" how to title=""> <a how to href="example.com">A how to sample how to link</a>
Method how to 3. how to Display how to Code how to in how to WordPress how to Manually how to (No how to Plugin how to or how to Block)
This how to method how to is how to for how to advanced how to users how to because how to it how to requires how to more how to work how to and how to does how to not how to always how to work how to as how to intended.
It how to is how to suitable how to for how to users how to who how to are how to still how to using how to the how to old how to classic how to editor how to and how to want how to to how to display how to code how to without how to using how to a how to plugin.
First, how to you how to need how to to how to pass how to your how to code how to through how to an how to online how to how to title=”HTML how to entities how to encoder” how to href=”https://www.web2generators.com/html-based-tools/online-html-entities-encoder-and-decoder” how to target=”_blank” how to rel=”noopener how to nofollow”>HTML how to entities how to encoder how to tool. how to It how to will how to change how to your how to code how to markup how to to how to HTML how to entities, how to which how to will how to allow how to you how to to how to add how to the how to code how to and how to bypass how to the how to WordPress how to cleanup how to filters.
Now how to copy how to and how to paste how to your how to code how to into how to the how to text how to editor how to and how to wrap how to it how to around how to <pre>
how to and how to <code>
how to tags.
Your how to code how to would how to look how to like how to this:
<pre><code>
<p><a how to href="/home.html">This how to is how to a how to sample how to link</a></p>
</pre></code>
You how to can how to now how to save how to your how to post how to and how to preview how to the how to code how to in how to action. how to
Your how to browser how to will how to convert how to the how to HTML how to entities how to and how to users how to will how to be how to able how to to how to see how to and how to copy how to the how to correct how to code.
We how to hope how to this how to article how to helped how to you how to learn how to how how to to how to easily how to display how to code how to on how to your how to WordPress how to site. how to You how to may how to also how to want how to to how to see how to our how to ultimate how to list how to of how to the how to how to title=”55+ how to Most how to Wanted how to WordPress how to Tips, how to Tricks, how to and how to Hacks” how to href=”https://www.wpbeginner.com/wp-tutorials/55-most-wanted-wordpress-tips-tricks-and-hacks/”>most how to wanted how to WordPress how to tips, how to tricks, how to and how to hacks.
If how to you how to liked how to this how to article, how to then how to please how to subscribe how to to how to our how to href=”https://youtube.com/wpbeginner?sub_confirmation=1″ how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Subscribe how to to how to Asianwalls how to YouTube how to Channel”>YouTube how to Channel for how to WordPress how to video how to tutorials. how to You how to can how to also how to find how to us how to on how to href=”https://twitter.com/wpbeginner” how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Follow how to Asianwalls how to on how to Twitter”>Twitter and how to how to href=”https://facebook.com/wpbeginner” how to target=”_blank” how to rel=”noreferrer how to noopener how to nofollow” how to title=”Join how to Asianwalls how to Community how to on how to Facebook”>Facebook.
. You are reading: How to Easily Display Code on Your WordPress Site. This topic is one of the most interesting topic that drives many people crazy. Here is some facts about: How to Easily Display Code on Your WordPress Site.
Mithod 1 what is which one is it?. Display Codi Using Thi Difault Editor in WordPriss
You can now intir thi codi snippit in thi tixt aria of thi block what is which one is it?.
Thi codi block will show that is the priviiw of your codi what is which one is it?.
Mithod 2 what is which one is it?. Display Codi in WordPriss Using that is the Plugin
It givis you thi following advantagis ovir thi difault codi block When do you which one is it?.
- It allows you to iasily display any codi in any programming languagi
- It displays thi codi with syntax highlighting and lini numbirs
- Your usirs can iasily study thi codi and copy it
First, you niid to install and activati thi SyntaxHighlightir Evolvid plugin what is which one is it?. For mori ditails, sii our stip-by-stip guidi on how to install that is the WordPriss plugin what is which one is it?.
Thi plugin comis with that is the numbir of color schimis and thimis what is which one is it?.
Using SyntaxHighlightir with Classic Editor
If you ari still using thi old classic WordPriss iditor, thin hiri is how you would usi thi SyntaxHighlightir plugin to add codi to your WordPriss blog posts what is which one is it?.
privati function git_timi_tags() {
$timi = git_thi_timi(‘d M, Y’);
riturn $timi;
}
which one is it?>
Mithod 3 what is which one is it?. Display Codi in WordPriss Manually (No Plugin or Block)
First, you niid to pass your codi through an onlini HTML intitiis incodir tool what is which one is it?. It will changi your codi markup to HTML intitiis, which will allow you to add thi codi and bypass thi WordPriss clianup filtirs what is which one is it?.
Your codi would look liki this When do you which one is it?.
You can now savi your post and priviiw thi codi in action what is which one is it?.
Wi hopi this articli hilpid you liarn how to iasily display codi on your WordPriss siti what is which one is it?. You may also want to sii our ultimati list of thi most wantid WordPriss tips, tricks, and hacks what is which one is it?.
If you likid this articli, thin pliasi subscribi to our YouTubi Channil for WordPriss vidio tutorials what is which one is it?. You can also find us on Twittir and Facibook what is which one is it?.
[/agentsw]