BLACK FRIDAY: 50% OFF all Pro plans Code: BLACKFRIDAY50
Pro from $10 a year or $30 lifetime, no code needed: Code: BLACKFRIDAY50
Ends Cyber Monday, 30 Nov. Lock in the price today. Code: BLACKFRIDAY50
Get 50% Off

Code Block

Free

Code with syntax colors, line numbers, highlighted lines, a file name and a copy button. It is free in Bright Addons Blocks Library on WordPress.org, and Bright Addons Blocks Pro includes it too.

Live demo

See the Code Block block

This is the block itself with its starting settings. Change any of them in the block sidebar.

functions.php PHP
<?php// Say hello to the visitor.function bright_hello( $name ) {	return 'Hello, ' . esc_html( $name ) . '!';}echo bright_hello( 'world' );

What you can set

Everything is in the block sidebar

The Code Block block has 5 settings panels. No code needed.

  • Code

    Set language, Code, File name (optional), Show the language and Language label (optional).

  • Lines

    Set line numbers, First line number, Highlight lines and Wrap long lines.

  • Copy button

    Set show the copy button, Button text and Text after copying.

  • Look

    Set theme, Font size (px) and Max height (px).

  • Colors

    Set 3 color settings.

How to use it

Add it in four steps

  1. Install the plugin

    Install Bright Addons Blocks Library from Plugins > Add New (search “Bright Addons Blocks”), or use Blocks Pro, which includes it.
  2. Add the block

    Open a page or post in the block editor, press +, and search for “Code Block”. It is in the Bright Addons category.
  3. Set it up

    Open the block sidebar and work through Code, Lines, Copy button, Look and Colors.
  4. Publish

    Preview the page on desktop, tablet and phone, then publish. The block loads its own CSS and JavaScript only on pages that use it.

Settings

The main settings

The full list, panel by panel, is in the Code Block guide.

Setting What it does Choices
Language (Code) Choose one. Plain text, HTML / XML, CSS, SCSS, JavaScript, TypeScript, JSX, TSX, JSON, PHP, Python, Bash / Shell
Code (Code) Shown exactly as typed. It is never run. –
File name (optional) (Code) Text you type. –
Show the language (Code) On or off. –
Language label (optional) (Code) Leave empty to use the language name. –
Line numbers (Lines) On or off. –
First line number (Lines) From 1 to 100000. –
Highlight lines (Lines) Line numbers separated by commas. Ranges like 5-7 work too. –
Wrap long lines (Lines) Off: long lines scroll sideways. –
Show the copy button (Copy button) On or off. –
Button text (Copy button) Text you type. –
Text after copying (Copy button) Text you type. –
Theme (Look) Choose one. Dark, Light
Font size (px) (Look) From 11 to 22. –

Questions

Good to know

Is the Code Block block free?

Yes. Code Block is one of the 62 free blocks of Bright Addons Blocks Library on WordPress.org. Bright Addons Blocks Pro includes it as well.

Do I need Elementor for this block?

No. It is a block for the WordPress block editor (Gutenberg). Elementor is not needed. If you use Bright Addons Pro for Elementor on the same site, both plugins work side by side.

Will it slow down my pages?

No. Each block loads only its own small CSS and JavaScript, and only on pages where it is used. Blocks you do not need can be switched off in Bright Blocks.

Does it work with my theme?

Yes. The blocks work with block themes and classic themes, and follow your theme fonts. Wide and full width alignment are supported.

Can I animate it?

Yes. Open Entrance animation in the sidebar and pick one of 40 animations with its duration and delay. Visitors who prefer reduced motion see no animation.

More blocks

Also in creative and content

Bright Addons Blocks

Get every block in one plugin

Blocks Pro has all 99 Pro blocks, the 62 free blocks, Pro effects for every block, Theme Templates and popups.