Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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' );
@dartiss
Copy link
Author

dartiss commented Apr 23, 2018

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 **

@dartiss
Copy link
Author

dartiss commented Apr 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment