I am placing a small code snippet in a WordPress.com web page. WordPress.com provides a "Code Block" option for formatting code.
Is there a way to add line numbers to the code in this code block?
Webmasters Stack Exchange is a question and answer site for pro webmasters. It only takes a minute to sign up.Sign up to join this community
Have you looked at WP plugins to replace the default editor? I personally have avoided the default editor for a couple of years.
A quick search of code editors for Wordpress will give you many different editors. Several of them have line number functionality. However, you will want to make sure they all work with the current "block" technology of the new Gutenberg Editor (about 2 years old).
Here's one with a screenshot of it's line numbers.
Whether they will specifically work inside of
code blocks as opposed to
inline as shown in the example would require testing. The one shown in the screenshot specifically says it doesn't work with "blocks in the visual editor".
From what I can tell, it looks like WordPress.com's SyntaxHighlighter Code Block shows line numbers, whereas their Code Block does not. My understanding is that the SyntaxHighlighter Code Block is a fancier, more full-featured code block type that's built into WordPress.com.
See the SyntaxHighlighter Code Block documentation for more info: