Write a plugin which adds a text to the footer
Description: Create a plugin called Footer Credit that prints Built with WordPress at the end of every page.
Hint:
- The plugin needs a header comment with
Plugin Name. - Use
add_action( 'wp_footer', ... ).
Solution
<?php
/**
* Plugin Name: Footer Credit
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'wp_footer', function () {
echo '<p class="credit">Built with WordPress</p>';
} );
Terminal output
$ wp plugin activate tc-footer-credit
Plugin 'tc-footer-credit' activated.
Success: Activated 1 of 1 plugins.
$ wp plugin list –name=tc-footer-credit –fields=name,status
name status
tc-footer-credit active
$ curl -s http://example.com/ | grep -o '<p class="credit">[^<]*</p>'
<p class="credit">Built with WordPress</p>
How it works
- WordPress reads the header comment and shows the plugin in the list.
- After activation, the file is loaded on every request, and the function waits for the
wp_footeraction.
Read Create a WordPress Plugin.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |