Monday, November 30, 2020
Home Blogging How to Easily Display Code on Your WordPress Site

How to Easily Display Code on Your WordPress Site

Do you need to display code in your WordPress weblog posts? If you happen to tried so as to add code like common textual content, then WordPress won’t display it appropriately.

WordPress runs your content material by means of a number of cleanup filters every time you save a submit. These filters are there to verify somebody doesn’t inject code by way of submit editor to hack your web site.

On this article, we are going to present you the right methods to simply display code in your WordPress website. We’ll present you totally different strategies, and you may select the one that most closely fits your wants.

Technique 1. Display Code Utilizing The Default Editor in WordPress

This technique is beneficial for newcomers and customers who don’t must display code fairly often.

Merely edit the weblog submit or web page the place you need to display the code. On the submit edit display screen, add a brand new code block to your submit.

Now you can enter the code snippet within the textual content space of the block.

After that, it can save you your weblog submit and preview it to see the code block in motion.

Relying in your WordPress theme, the code block could look totally different in your web site.

Technique 2. Display Code in WordPress Utilizing a Plugin

For this technique, we will probably be utilizing a WordPress plugin to display code in your weblog posts. This technique is beneficial for customers who usually display code of their articles.

It provides you the next benefits over the default code block:

  • It permits you to simply display any code in any programming language
  • It display the code with syntax highlighting and line numbers
  • Your customers can simply examine the code and replica it

First, you should set up and activate the SyntaxHighlighter Advanced plugin. For extra particulars, see our step-by-step information on easy methods to set up a WordPress plugin.

Upon activation, you’ll be able to go forward and edit the weblog submit the place you need to display the code. On the submit edit display screen, add the ‘SyntaxHighlighter Code’ block to your submit.

You’ll now see a brand new code block within the submit editor the place you’ll be able to enter your code. After including the code, you should choose the block settings from the fitting column.

First, you should choose the language in your code. After that, you’ll be able to flip off line numbers, present first line quantity, spotlight any line you need, and switch off the characteristic to make hyperlinks clickable.

As soon as you might be carried out, save your submit and click on on the preview button to see it in motion.

You may Also Like : 40+ Popular Universities that are Using WordPress

The plugin comes with quite a few colour schemes and themes. To alter the colour theme, you should go to Settings » SyntaxHighlighter web page.

From the settings web page, you’ll be able to choose a colour theme and alter SyntaxHighlighter settings. It can save you your settings to see a preview of the code block on the backside of the web page.

Utilizing SyntaxHighlighter with Basic Editor

In case you are nonetheless utilizing the outdated basic WordPress editor, then right here is how you’d use SyntaxHighlighter plugin so as to add code to your WordPress weblog posts.

Merely wrap your code round sq. brackets with the language identify. For instance, if you’ll add PHP code, then you’ll add it like this:

private function get_time_tags() {
$time = get_the_time(‘d M, Y’);
return $time;

Equally, in case you needed so as to add an HTML code, then you’ll wrap it across the HTML shortcode like this:

<a href="">A pattern hyperlink</a>

Technique 3. Display Code in WordPress Manually (No Plugin or Block)

This technique is for superior customers as a result of it requires extra work and doesn’t at all times work as meant.

It’s appropriate for customers who’re nonetheless utilizing the outdated basic editor and need to display code with out utilizing a plugin.

First, you should go your code by means of a web-based HTML entities encoder instrument. It should change your code markup to HTML entities, which can let you add the code and bypass the WordPress cleanup filters.

Now copy and paste your code within the textual content editor and wrap it round <pre> and <code> tags.

Your code would appear like this:

&lt;p&gt;&lt;a href=&quot;/home.html&quot;&gt;This is a sample link&lt;/a&gt;&lt;/p&gt;

Now you can save your submit and preview the code in motion. Your browser will convert the HTML entities and customers will have the ability to see and replica the proper code.

We hope this text helped you learn to simply display code in your WordPress website. You may additionally need to see our final record of the most needed WordPress ideas, methods, and hacks.

If you liked this article, make sure to hit the bell for getting our latest updates and share this article with your friends in every social media platforms.



Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

How to Signup for Godaddy Affiliate Program & Start Making Money

GoDaddy is likely one of the well-liked model names out there of area and web-hosting. They are well-liked for a numerous cause, and so they...

How To Start Selling Website on Flippa: A Beginner’s Guide To Success

If you may have been working on-line for lengthy and into Website flipping, Flippa is one identify that you need to have heard of. Flippa is a...

How to Fix Your Connection is Not Private Error (Site Owners Guide)

Are you seeing ‘Your connection is not private’ error in your WordPress web site? This is the error message you’ll see on Google Chrome. The...

How to Fix the WordPress White Page of Death (Step by Step)

The WordPress white page of dying is one of the most widespread WordPress errors. It can also be one of the most irritating ones as...

Recent Comments