Here is an example of the final result of a Gist block that includes PHP code: Gist is a free GitHub service for hosting code snippets. ¿How do we Include Code Snippets in Nelio?Īfter trying different ways to include code snippets in WordPress over time, we have finally opted for writing the code snippets directly in Gist and create an additional block to import the Gists in the block editor. The adaptation to the block editor was done by Ian Dunn, as you can see here. I don’t want to stop mentioning that the source code of the SyntaxHighlighter Evolved plugin was made by Alex Mills, who recently left us after losing the battle against leukemia. If you have the need to add code snippets in your content, it is much more recommended to use the block from the SyntaxHighlighter Evolved plugin instead of the default code block of WordPress. Apart from that, it behaves like a paragraph block. It simply uses a monospaced font and does not create a new block when pressing the enter key but a new line. The SyntaxHighlighter Evolved plugin allows us to add blocks of code in Gutenberg to include code snippets in our posts and pages.īut… does not already Gutenberg include a block of code by default? The answer is yes, but this block of code that the block editor provides does not highlight the syntax of your code. The good news is that it has now been updated and includes support for adding blocks of code in the WordPress block editor. I remember that we had used this plugin on our website for code syntax highlighting some time ago. Among the most popular plugins for this we have Syntax Highlighter (now called Syntax Highlighter Evolved). Something, by the way, very easy to do selecting the code with your mouse and using the keyboard shortcut ctrl + alt + x in Mac OS X to wrap it with the code tag.Īnother option was to use a third-party shortcode or a plugin that would help us include code snippets and highlight its syntax. If you only wanted to add a bit of code composed of just a few words, you could insert the code between and tags. This is useful in the case of code fragments that occupy multiple lines. One of them was to put the code fragments between the HTML labels and. To include code snippets into the classic editor you may follow several different paths. But I will also tell you that it has required a previous effort on our part. Nowadays including code snippets in the posts of our blog it’s easier than with the classic editor. The answer depends on the taste of the writer, but in my case I’d say “yes”. Is this now easier than with the classic editor? But if you have a blog in which more than once you talk about technical issues, you’ll probably need to include code snippets (PHP, JavaScript, and so on) within your content. We were promised that everything would be easier with Gutenberg. But what do you expect us to do if new things appear about it in the news on a daily basis? The WordPress block editor, also known as Gutenberg by its codename, continues to monopolize much of our blog posts.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |