Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin

tommcfarlin/00-my_content.php Secret

Created Apr 6, 2017
Embed
What would you like to do?
[WordPress] Properly Filtering Post Content (And Understanding apply_filters)
<?php
$post->post_content = $my_content;
<?php
$post->post_content = apply_filters( 'the_content', $my_content );
<?php
/**
* Assume $contents is an array of information we want to convert into content for a post.
*/
$new_content = '';
foreach ( $contents as $line ) {
if ( false === strpos( $line, $name ) ) {
$new_content .= $line;
}
}
$post->post_content = $new_content;
<?php
/**
* Assume $contents is an array of information we want to convert into content for a post.
*/
$new_content = '';
foreach ( $contents as $line ) {
if ( false === strpos( $line, $name ) ) {
$new_content .= $line;
}
}
$post->post_content = apply_filters( 'the_content', $new_content );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.