Created
November 20, 2024 13:10
-
-
Save laxmariappan/3ee0629f4c3eb1e0a5f4aa1947b312fd to your computer and use it in GitHub Desktop.
Example of WordPress Hooks and filters
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: LWP Announcement | |
| * Description: LWP Announcement | |
| * Version: 1.0.1 | |
| * Author: Lax Mariappan | |
| */ | |
| add_action('wp_head', 'my_announcement'); | |
| /** | |
| * Register the announcement action. | |
| */ | |
| function my_announcement() { | |
| do_action('announcement_action'); | |
| } | |
| add_filter('announcement_filter','my_filter',10,2); | |
| /** | |
| * Filters the announcement text. | |
| */ | |
| function my_filter($text, $name){ | |
| return $text . ' filtered' . $name; | |
| } | |
| add_action('announcement_action','show_announcement'); | |
| function show_announcement(){ | |
| $announcement = apply_filters('announcement_filter', '<p>This is my announcement</p>','Lax'); | |
| echo $announcement; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment