Created
April 23, 2018 10:35
-
-
Save dartiss/d4240720c69ce8f32860eb7096378dd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function embed_code( $content ) { | |
global $post; | |
$i = 1; | |
while ( $i < 6 ) { | |
$code = 'CODE' . $i; | |
$html = get_post_meta( $post->ID, $code, false ); | |
$content = str_replace( '{{' . $code . '}}', $html[0], $content ); | |
$i++; | |
} | |
return $content; | |
} | |
add_filter( 'the_content', 'embed_code' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Super-simple method of embedding code into a WordPress post without the editor modifying it.
Once the above code is in place, add a custom field named CODEx, where x is a number between 1 and 5. The field value is your code to be embedded. Then, in your post, add {{CODEx}} where you wish the code to appear (again, replace the x with the appropriate number).
** VIP full coding-standards compliant **