My first WordPress plugin

415 views
367 views

Published on

How to make a very basic WordPress Plugin using the "the_content" filter to modify the content of each post

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
415
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

My first WordPress plugin

  1. 1. A first plugin : playing with filters Pat Lockley @pgogy / @patlockley
  2. 2. Step 1 Go to wp-content/plugins/ on your server and make a folder or Make a folder anywhere (if brave)
  3. 3. Step 2 : Step harder Let’s call the folder “lightningtalk” In this folder make a file called “lightningtalk. php”
  4. 4. Step 3 Let’s call the folder “lightningtalk” In this folder make a file called “lightningtalk. php”
  5. 5. Step 4 in this file add the characters <?PHP
  6. 6. Step 5 /* Plugin Name: Lightning Talk Description: My First Plugin Version: 0.1 */
  7. 7. Step 6 now add … function change_content($content){ return $content; } add_filter(“the_content”, “change_content”);
  8. 8. Step 7 So if you make this on a server, go the the plugins page and enable it Or zip the folder up, upload it, and then go to the plugins page and enable it
  9. 9. uh oh…..
  10. 10. Step 8 ABSOLUTELY NOTHING
  11. 11. Step 9 function change_content($content){ return “Hello world”; }
  12. 12. Step 10 function change_content($content){ // The . symbol means merge strings in PHP return $content . “ Hello world”; }
  13. 13. Step 11 function change_content($content){ // The . symbol means merge strings in PHP return $content . “<a href=’url’>Visit us</a>”; }
  14. 14. Step 12 function change_content($content){ // str_replace - this is PHP for ctrl + H return str_replace(“Company name”,“<a href=’url’>Company name</a>”, $content ); }
  15. 15. Step 13 function change_content($content){ // str_replace - this is PHP for ctrl + H return str_replace(“Company name”,“<a href=’url’>Company name</a>”, $content ); }
  16. 16. Step 14 function change_content($content){ // str_replace - this is PHP for ctrl + H return str_replace(“Company name”,“<a href=’url’>Company name</a>”, $content ); }
  17. 17. Step 15 function change_content($content){ global $post; if($post->post_title==”hello”){ return str_replace(“Company name”,“<a href=’url’>Company name</a>”, $content ); }else{ return $content; } }

×