Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpataki/d240ae31c7db17db7e30 to your computer and use it in GitHub Desktop.
Save danielpataki/d240ae31c7db17db7e30 to your computer and use it in GitHub Desktop.
Showing code
<strong>bold text</bold>
<pre class="line-numbers"><code class='language-php'>add_action( 'admin_notices', 'show_mot_text' );
function show_mot_text() {
$text = get_motivation_text();
echo "<p id='wp-admin-motivation'>$text</p>";
}</code></pre>
To add the motivation text to the top area, simply hook a function into admin_notices, like so:
<pre>add_action( 'admin_notices', 'show_mot_text' );
function show_mot_text() {
$text = get_motivation_text();
echo "&lt;p id='wp-admin-motivation'&gt;$text&lt;/p&gt;";
}</pre>
<?php
/*
* Plugin Name: Smart Code Escape
* Plugin URI: https://github.com/danielpataki/Smart-Code-Escape
* Description: Converts less than, greater than and ampersand characters to their HTML
entities within pre tags before they are output on the page. You will always see the
non-escaped version in the editor, making code easy to modify. It Will not convert code
tags directly within pre tags to support Prism-style highlighting.
* Version: 1.1
* Author: Daniel Pataki
* Author URI: http://danielpataki.com
* License: GPL v2
* Licence URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
function smart_code_escape_pre( $data ) {
preg_match('@(<code.*>)(.*)(<\/code>)@isU', $data[2], $matches );
if( !empty( $matches ) ) {
return $data[1] . $matches[1] . str_replace( array( '&', '<', '>' ), array( '&amp;', '&lt;', '&gt;' ), $matches[2] ) . $matches[3] . $data[3];
}
else {
return $data[1] . str_replace( array( '&', '<', '>' ), array( '&amp;', '&lt;', '&gt;' ), $data[2] ) . $data[3];
}
}
add_filter( 'the_content', 'smart_code_escape_content', 9 );
function smart_code_escape_content( $content ) {
$content = preg_replace_callback('@(<pre.*>)(.*)(<\/pre>)@isU', 'smart_code_escape_pre', $content );
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment