Last active
May 17, 2020 04:31
-
-
Save raazon/cb86f82901165d47db8c6a7c7fae781b to your computer and use it in GitHub Desktop.
WordPres filter content if find any certain word
This file contains hidden or 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 | |
/** | |
* Filter content if find any certain word. | |
* @author Razon Komar Pal | |
*/ | |
function ic_filter_content_sample($content) | |
{ | |
// for single post | |
if (is_single()) { | |
$new_content = '<p>This is added to the bottom of all post and page content</p>'; | |
$search = 'Welcome to WordPress'; | |
if (strpos($content, $search) !== false) { | |
$content = $new_content . $content; | |
} | |
return $content; | |
} | |
return $content; | |
} | |
add_filter('the_content', 'ic_filter_content_sample'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment