I had been looking for a system to show code in WordPress post for a long time, and that the usual codes included in the writing panel did not work on all occasions. There are times even that I have chosen to include the code in image capture mode when neither code nor pre nor textarea served me.
The problem is that sometimes WordPress can not distinguish when a code is being displayed to be seen or to be executed, and there are certain commands, usually those that can be included in the content or comments loop, which are not they adapt well to be included in an entry.
And in a blog like WordPress Help, that in many of the entries we offer code to be copied by the reader to modify its templates or add functions, needed something that would allow to show code without that it interfered with the presentation of the blog.
Well, the search ended because I found WP-Syntax a plugin based on Ghesi (Generic Syntax Highlighting) that not only easy ita the way to include code in your entries without trying to execute but it does it in the most elegant and visually attractive way possible.
The process to install it is as simple as any other plugin, if you hurry me more because you do not have a configuration options window or anything like that. You just have to download it, unzip it and upload the folder " wp-syntax " to " wp-content / plugins " of the installation of your WordPress.
From there alone you have to take into account the procedure to insert code in your posts:
1. You must keep in mind that you will have to use the HTML mode of your editor to make it work.
2. Then you have two ways to include code in your posts:
- With line numbering:
- Without line numbering:
> YOUR CODE
Where " LANGUAGE "Is the name of the programming language whose code you will include be it php, html, xml, xhtml, bash, java, ruby, and many more that are supported; you have the complete list in the sidebar of this page where it says "supported languages". And if you do not indicate any default language is PHP.
The effects you can get are as in this example:
3  4
28  [ ? php
// ** MySQL Options ** //
define ( 'DB_NAME' 'database name' ) ; // The name of the database
defines ( 'DB_USER' 'usuariomysql' ) ; // Your MySQL user
define  ( 'DB_PASSWORD' 'clavemysql' ) ; // … and clave
define  ( 'DB_HOST' 'localhost' ) ; // 99% of the time you do not have to change this ]
define ( 'DB_CHARSET' 'utf8' ) ;
define  ( 'DB_COLLATE' '' ) ;
// Change SECRET_KEY to a single phrase. You will not have to remember it later,
// so make it long and complicated. Visit https://www.grc.com/passwords.htm
// to create a long key, or put what you want.
define ( 'SECRET_KEY' 'put your single phrase here' ) ; // Change this to a single phrase.
// You can have multiple installations in a single database if you give them a unique prefix
$ table_prefix = 'wp_ '; // Only numbers, letters and underline!
// Change this to translate WordPress. An MO file for the
// chosen language must be installed in wp-content / languages.
// For example, install de.mo in wp-content / languages and sets WPLANG to 'de'
// to have it in German.
define ( 'WPLANG' ] 'es_ES' ) ;
/ * That's it, stop modifying things. Good blogging * /
define ( 'ABSPATH' dirname ( __ FILE __ ) . '/' ) ;
require_once ( ABSPATH . 'wp-settings.php ') ;
So you know, if you usually include code in your posts to show it to others this is one of the most effective, although not perfect because it includes extra spaces. We will keep looking.