-
-
Save tommcfarlin/a14b284a07d515fe2b08c62ec48ff8fd to your computer and use it in GitHub Desktop.
[WordPress] Properly Filtering Post Content (And Understanding apply_filters)
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 | |
$post->post_content = $my_content; |
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 | |
$post->post_content = apply_filters( 'the_content', $my_content ); |
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 | |
/** | |
* 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; |
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 | |
/** | |
* 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