My first WordPress plugin
Upcoming SlideShare
Loading in...5
×
 

My first WordPress plugin

on

  • 199 views

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

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

Statistics

Views

Total Views
199
Views on SlideShare
198
Embed Views
1

Actions

Likes
0
Downloads
2
Comments
0

1 Embed 1

https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    My first WordPress plugin My first WordPress plugin Presentation Transcript

    • A first plugin : playing with filters Pat Lockley @pgogy / @patlockley
    • Step 1 Go to wp-content/plugins/ on your server and make a folder or Make a folder anywhere (if brave)
    • Step 2 : Step harder Let’s call the folder “lightningtalk” In this folder make a file called “lightningtalk. php”
    • Step 3 Let’s call the folder “lightningtalk” In this folder make a file called “lightningtalk. php”
    • Step 4 in this file add the characters <?PHP
    • Step 5 /* Plugin Name: Lightning Talk Description: My First Plugin Version: 0.1 */
    • Step 6 now add … function change_content($content){ return $content; } add_filter(“the_content”, “change_content”);
    • 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
    • uh oh…..
    • Step 8 ABSOLUTELY NOTHING
    • Step 9 function change_content($content){ return “Hello world”; }
    • Step 10 function change_content($content){ // The . symbol means merge strings in PHP return $content . “ Hello world”; }
    • Step 11 function change_content($content){ // The . symbol means merge strings in PHP return $content . “<a href=’url’>Visit us</a>”; }
    • 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 ); }
    • 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 ); }
    • 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 ); }
    • 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; } }