Created
April 20, 2022 11:15
-
-
Save fahdi/b4d2816142531bedd70ff1919d0a34f3 to your computer and use it in GitHub Desktop.
Examples for WP filter
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 | |
| /* | |
| Plugin Name: Filter the content to remove ADULTKEYWORD. This is an example plugin | |
| */ | |
| add_filter('the_content', 'fm_filter_the_main_loop', 1); | |
| function fm_filter_the_main_loop($content) | |
| { | |
| // Check if we're inside the main loop in a single Post. | |
| if (is_singular() && in_the_loop() && is_main_query()) { | |
| $content = str_replace('ADULTKEYWORD', '...', $content); | |
| } | |
| return $content; | |
| } | |
| add_filter('the_title', 'fm_format_title', 1); | |
| function fm_format_title($title) | |
| { | |
| if (is_singular() || is_front_page()) { | |
| $title = $title." - by ". get_the_author(); | |
| } | |
| return $title; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment