Skip to content

Instantly share code, notes, and snippets.

@laxmariappan
Created November 20, 2024 13:10
Show Gist options
  • Save laxmariappan/3ee0629f4c3eb1e0a5f4aa1947b312fd to your computer and use it in GitHub Desktop.
Save laxmariappan/3ee0629f4c3eb1e0a5f4aa1947b312fd to your computer and use it in GitHub Desktop.
Example of WordPress Hooks and filters
<?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