Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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