Using the Code Block

When you’re working in WordPress there will be many times when you need to present code to your viewers. The WordPress editor provides a Code block that makes it easy to add and share code. The main advantage of the block is that it will keep the spacing used in the code without trying to format the text. Follow the steps below to use the Code block for your WordPress posts or pages.

Need a home for your WordPress site? Check out InMotion’s WordPress Hosting solutions for secure, optimized servers that will meet your performance and budget needs.

Using the Code Block

The Code block is very simple to use. However, please note that the appearance of the block will be determined by the theme used in your WordPress installation. As with any WordPress block, you will need to be logged into the WordPress Administrator Dashboard in order to add or edit your posts or pages. Here’s an example of the code block in action:

?php

require "vendor/autoload.php";

$robo = '[email protected]';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;


$developmentMode = true;
$mailer = new PHPMailer($developmentMode);

There are no options that come with the use of this block. Basically, you add it to your page or post, then paste the code within it. The only option that you have will be the usual Additional CSS option provided in the block properties that is a part of all blocks.

  1. Open an existing page/post or create a new one.
  2. Click on the circled + sign in order to add a new block.
  3. Search for Code, or go to the Formatting section and select the Code block.
Using the Code block
Using the Code Block
  1. Once the block appears, simply paste in your code when you’re ready.

Congratulations! You now know how to add and use a Code block within the WordPress editor. To learn more about using WordPress, please go to our WordPress Educational Channel.

AC
Arnel Custodio Content Writer I

As a writer for InMotion Hosting, Arnel has always aimed to share helpful information and provide knowledge that will help solve problems and aid in achieving goals. He's also been active with WordPress local community groups and events since 2004.

More Articles by Arnel

Comments

It looks like this article doesn't have any comments yet - you can be the first. If you have any comments or questions, start the conversation!

Was this article helpful? Let us know!