Try Tuts+ Premium, Get Cash Back!
Your First WordPress Plugin: Simple Optimization

Your First WordPress Plugin: Simple Optimization

Tutorial Details
  • Program: Wordpress
  • Version: 2.5.1+
  • Difficulty: Beginner
  • Estimated Completion Time: 30 minutes

WordPress is the largest blogging platform available on the internet today; and with the official release of version three just around the corner, it’s only going to get bigger. As such, over the next few self-contained tuts, we’re going to learn the ins and outs of WordPress plugin development, starting with the creation of our first simple plugin, “Simple Optimization.”


Step 0 Before we Begin

This tutorial is going to assume that you have at least a beginner’s understanding of PHP and the WordPress syntax. Though we’ll be covering everything, some knowledge beforehand will help you grasp the concepts much more easily. I’ll also assumes that you have a WP blog setup and ready to go.


Step 1. What our Plugin Does

The very first step, when writing a WP plugin, is to determine everything you want it to do. Since this is our first plugin, we won’t do anything too drastic. Let’s create something which will speed up our blog; our pages will render faster, and we’ll also do a little SEO to improve our search rank and findability.

“Always create a list of what you want your plugin to actually do before you write any code!”

Remove useless meta tags:

  • “rsd_link” – Really Simple Discovery Link
  • “wlwmanifest_link” – Windows Live Writer link
  • “wp_generator” – WordPress version number

Remove unnecessary filters:

  • “wptexturize” – Curly quotes
  • “wp_filter_kses” – HTML in user profiles

SEO:

  • Insert post tags into <head> as keywords
  • Insert post excerpt into <head> as description

Step 2. Laying the Groundwork

To start, navigate to your plugins folder (“/wp-content/plugins/”), and create a new folder. We’ll call ours “simple-optimization.” Next, inside of this folder we’re going to need to create two files. The first will be the actual plugin file (named “main.php”), and the second will be the mandatory README (“readme.txt”). We’re going to leave readme.txt empty for the time being; so open main.php in your preferred text-editor and copy in the code below.

    <?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
.
Any other notes about the plugin go here
.
*/
?>

This text is the bare-bones minimum needed for a plugin to appear in the WordPress plugin directory. You’ll obviously need to fill each part as you see fit.


Step 3. Adding Features

The first two features we’re going to implement will also be the simplest. By default, WordPress adds several meta-tags to the <head> section of your blog, but the simple fact of the matter is that these meta-tags have absolutely no value at all; so we’re simply going to stop WordPress from adding them. Anytime WordPress performs an action, it’s either called a filter or an action, and we can either remove or manipulate these filters and actions (you can find a list of all the filters here, and all the actions here). In this case, we want to remove the various actions that add those meta-tags.

To do so, we use a very simple function called “remove_action(‘action’,'function’)”. This function will remove the function declared in the second parameter from the action, the first parameter.

// Clean up wp_head
// Remove Really simple discovery link
remove_action('wp_head', 'rsd_link');
// Remove Windows Live Writer link
remove_action('wp_head', 'wlwmanifest_link');
// Remove the version number
remove_action('wp_head', 'wp_generator');

The same exact same principle applies to the two filters we’re going to remove:

// Remove curly quotes
remove_filter('the_content', 'wptexturize');
remove_filter('comment_text', 'wptexturize');

// Allow HTML in user profiles
remove_filter('pre_user_description', 'wp_filter_kses');

Step 4. SEO

Now that we’ve cut out that bloat, let’s ensure our blog has some basic SEO; meaning, let’s make sure we have keywords per-page, which correspond to that page and change the description to match more with the article. For our keywords, we’re going to grab the tags of the current page/post. This is made super simple by the function “wp_get_post_tags()”. wp_get_post_tags will return an array of tags from the current post. We can then easily format this array into a string and place it within our header (inside the function “wp_head()”, that every theme should have in it already) by attaching our function to the wp_head action.

Let’s start out by creating a new function, tags_to_keywords(), and, inside of this function, we’ll write a simple if statement, which checks to see if the current page is a single post or page (using the WP functions: is_single() and is_page()). Next, we’ll create a variable inside this if statement, named $tags, and set its content to the function wp_get_post_tags(); however, in order for this function to work, we need to pass in a parameter of “post_id”. The easiest way for us to obtain that is to globalize the WP variable $post which contains the post ID ($post->ID, $post is an object which is why we’re calling its values like so).

// SEO
// add tags as keywords
function tags_to_keywords(){
    global $post;
    if(is_single() || is_page()){
        $tags = wp_get_post_tags($post->ID);
    }
}

Next, we’ll use a foreach to filter through the $tags data, and create a new array with only the information we want ($tag_array). Following that, we’ll implode the array into a string and separate each item from the array with a comma and space ($tag_string). Then, we’ll create another if statement that checks to see if $tag_string has a value (meaning, do we have any tags for the post) and if it does, echo out the final HTML.

function tags_to_keywords(){
    global $post;
    if(is_single() || is_page()){
        $tags = wp_get_post_tags($post->ID);
        foreach($tags as $tag){
            $tag_array[] = $tag->name;
        }
        $tag_string = implode(', ',$tag_array);
        if($tag_string !== ''){
            echo "<meta name='keywords' content='".$tag_string."' />\r\n";
        }
    }
}

The last thing we need to do now is attach our new function with the wp_head action. To do this, we’re going to call add_action(‘action’,'function’), and pass it the parameters “wp_head” and “tags_to_keywords” (in that order).

add_action('wp_head','tags_to_keywords');

To further increase our SEO, we’re going to add our description meta-data to the header as well, using the same method as the keywords. Once we have the if statement rewritten, we’re going to create a new variable $all_post_content and fill it using the WP function wp_get_single_post() (and pass the parameter of $post->ID). This will give us an object full of all the data about our post. With this variable, we can create a description using the actual content of the post, but we’re going to shorten it down to one hundred characters using the function substr ($excerpt). And then, we’ll just echo out the HTML with the excerpt written in. (Optionally, you can also add an else statement, and echo your blog description using the function get_bloginfo(‘description’).)

// add except as description
function excerpt_to_description(){
    global $post;
    if(is_single() || is_page()){
        $all_post_content = wp_get_single_post($post->ID);
        $excerpt = substr($all_post_content->post_content, 0, 100).' [...]';
        echo "<meta name='description' content='".$excerpt."' />\r\n";
    }
    else{
        echo "<meta name='description' content='".get_bloginfo('description')."' />\r\n";
    }
}
add_action('wp_head','excerpt_to_description');

Step 5. Optimizing the Database

The final feature for our plugin is going to optimize our database tables by removing overhead (useless/excess data in a SQL table created by manipulating the database). To begin, we’ll create a new function (optimize_database), and inside of it, we’re going to call the global WPDB variable ($wpdb). That way, we can interact with the database, without having to re-enter our authentication details. $wpdb has several methods you can use to interact with and retrieve information from the database (Full list here), but we’re only going to be using one, get_results. Using get_results with the parameters of “SHOW TABLES” and “ARRAY_A” will return to us an associative array of all the table names in the database. At that point, we can use a foreach to loop through each of the array values (using array_values to get the table name, because of how it’s layered by the function) and use another $wpdb method, query to run the optimize command (“OPTIMIZE TABLE _____”).

//Optimize Database
function optimize_database(){
    global $wpdb;
    $all_tables = $wpdb->get_results('SHOW TABLES',ARRAY_A);
    foreach ($all_tables as $tables){
        $table = array_values($tables);
        $wpdb->query("OPTIMIZE TABLE ".$table[0]);
    }
}

While this function works, it will never actually run because WordPress has no way to know to run it. Luckily, WordPress has a feature called cron, which schedules functions to run at specific intervals (daily, weekly, etc…); this is perfect for us, since we want to frequently optimize our database. To use Cron, we’re going to create a new function (simple_optimization_cron_on), and fill it with another function call to wp_schedule_event(). To work, wp_schedule_event needs three things: a time to run, an interval between each run, and a function to call; so we’ll pass it the parameters: ‘time()’ (we’ll assume that whenever the cron event is created is a good time to call the function), ‘daily’, ‘optimize_database’ in that order.

function simple_optimization_cron_on(){
    wp_schedule_event(time(), 'daily', 'optimize_database');
}

Great, now we have our optimize_database function being added to the WP cron list, or we would if we were to call the simple_optimization_cron_on function. It’s really unsafe and is a bad practice to call your own event addition functions, because through some arbitrary system of events, it could cause the function to be called multiple times. WordPress happens to have a set of specific hooks for plugins to solve this problem: register_activation_hook and register_deactivation_hook. These functions are called when a plugin is turned on (activated) and turned off (deactivated). This way, our cron function can only be added once. Now, we have the ability to remove the cron event if the plugin stops being used. To work, these functions need two pieces of information: the url to the file that has the activation and deactivation functions (99% of the time “__FILE__” will work perfectly here), and the name of the activation and deactivation function. We’ll also create a new function (simple_optimization_cron_off), and fill it with a call to another function (wp_clear_scheduled_hook(‘optimize_database’)) to delete our cron event.

function simple_optimization_cron_off(){
    wp_clear_scheduled_hook('optimize_database');
}
register_activation_hook(__FILE__,'simple_optimization_cron_on');
register_deactivation_hook(__FILE__,'simple_optimization_cron_off');

Step 6. Filling out the ReadMe

The last thing we need to do for our new plugin is fill in the readme.txt file. The readme.txt file is used by the WordPress Plugin directory to display all the information you provide it about your plugin. The best way to learn how to write an effective readme.txt file is to download the default from WP, and alter it accordingly to fit your plugin. Since ours was so simplistic, this is what I personally ended up with:

=== Simple Optimization ===
Contributors: Jonathan Wolfe
Plugin link: http://net.tutsplus.com/
Tags: simple, optimization, keywords, tags, description, SEO, optimize, database
Requires at least: 2.5.1
Tested up to: 2.9.2
Stable tag: trunk

Silently adds several optimizing functions to the WordPress back-end to make your blog or site run faster.

== Description ==

Simple Optimization adds several functions to WordPress that help trim the fat from the system and also clean up after itself a little bit all leading to a faster loading time for your blog or website.

**Features**
_Remove useless meta tags:_
* "rsd_link" - Really Simple Discovery Link
* "wlwmanifest_link" - Windows Live Writer link
* "wp_generator" - WordPress version number
_Remove useless filters:_
* "wptexturize" - currly quotes
* "wp_filter_kses" - HTML in user profiles
_SEO:_
* Insert post tags into <head> as keywords
_Routinely optimize the database_


== Installation ==

1. Download, unzip and upload to your WordPress plugins directory
2. activate the plugin within you WordPress Administration

That’s it!

You just successfully wrote your first WordPress plugin, which is working and ready for the WP Plugins Directory. Along the way, you learned about filters and actions, using WP global objects, a lot about the WordPress nomencalture, how to interact with the database, cron events, and activation/deactivation hooks. If you have any questions, please leave a comment and I’ll respond as soon as I can.

The final code:

<?php
/*
Plugin Name: Simple Optimization
Plugin URI: http://net.tutsplus.com
Description: A super-simple plugin to improve your blog
Version: 1.0
Author: Jonathan Wolfe
Author URI: http://fire-studios.com
License: GPL2
.
This plugin written for NETTUTS at http://net.tutsplus.com
.
*/

// Clean up wp_head
// Remove Really simple discovery link
remove_action('wp_head', 'rsd_link');
// Remove Windows Live Writer link
remove_action('wp_head', 'wlwmanifest_link');
// Remove the version number
remove_action('wp_head', 'wp_generator');

// Remove curly quotes
remove_filter('the_content', 'wptexturize');
remove_filter('comment_text', 'wptexturize');

// Allow HTML in user profiles
remove_filter('pre_user_description', 'wp_filter_kses');

// SEO
// add tags as keywords
function tags_to_keywords(){
    global $post; // Get access to the $post object
    if(is_single() || is_page()){ // only run on posts or pages
        $tags = wp_get_post_tags($post->ID); // get post tags
        foreach($tags as $tag){ // loop through each tag
            $tag_array[] = $tag->name; // create new array with only tag names
        }
        $tag_string = implode(', ',$tag_array); // convert array into comma seperated string
        if($tag_string !== ''){ // it we have tags
            echo "<meta name='keywords' content='".$tag_string."' />\r\n"; // add meta tag to <head>
        }
    }
}
add_action('wp_head','tags_to_keywords'); // Add tags_to_keywords to wp_head function
// add except as description
function excerpt_to_description(){
    global $post; // get access to the $post object
    if(is_single() || is_page()){ // only run on posts or pages
        $all_post_content = wp_get_single_post($post->ID); // get all content from the post/page
        $excerpt = substr($all_post_content->post_content, 0, 100).' [...]'; // get first 100 characters and append "[...]" to the end
        echo "<meta name='description' content='".$excerpt."' />\r\n"; // add meta tag to <head>
    }
    else{ // only run if not a post or page
        echo "<meta name='description' content='".get_bloginfo('description')."' />\r\n"; // add meta tag to <head>
    }
}
add_action('wp_head','excerpt_to_description'); // add excerpt_to_description to wp_head function

//Optimize Database
function optimize_database(){
    global $wpdb; // get access to $wpdb object
    $all_tables = $wpdb->get_results('SHOW TABLES',ARRAY_A); // get all table names
    foreach ($all_tables as $tables){ // loop through every table name
        $table = array_values($tables); // get table name out of array
        $wpdb->query("OPTIMIZE TABLE ".$table[0]); // run the optimize SQL command on the table
    }
}
function simple_optimization_cron_on(){
    wp_schedule_event(time(), 'daily', 'optimize_database'); // rdd optimize_database to wp cron events
}
function simple_optimization_cron_off(){
    wp_clear_scheduled_hook('optimize_database'); // remove optimize_database from wp cron events
}
register_activation_hook(__FILE__,'simple_optimization_cron_on'); // run simple_optimization_cron_on at plugin activation
register_deactivation_hook(__FILE__,'simple_optimization_cron_off'); // run simple_optimization_cron_off at plugin deactivation
?>

Tags: Wordpress
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://aext.net AEXT.NET MAGAZINE

    Interesting tutorial! Thank you!

  • http://www.abu-farhan.com Abu Farhan

    Thank you for this tutorial, I looking for easy tutorial about WP plugin

  • http://www.andrislinz.ch Andris

    That was very informative. I always wondered: what are the basic needs for a wordpress plugin? You answered my question here pretty well. Thanx.

  • http://superdit.com aditia

    thanks for the tutorial, btw I wonder, is the optimization method remove the duplicate post on the database or not, because before make the post public, I saving the post many times and wordpress create duplicate post field in the table, looking some answer here

    • John

      It’s not deleting duplicate data. It uses a built in mysql function to clean up the overhead. You wouldnt even know this data was there unless you looked at the dbms.

    • http://fire-studios.com Jonathan Wolfe
      Author

      The optimize function in the plugin we made here does not do that, but you can do it manually. Just run the SQL ” DELETE FROM wp_posts WHERE post_type = ‘revision’; ” on your database via phpMyAdmin (or the like).

      • http://superdit.com aditia

        thanks for your advice jonathan, now i’m trying to do it carefully.. thanks again..

      • http://viniciusalmeida.com.br Vinicius Almeida

        This can be inserted after the “foreach” function “optimize_database ()”!?
        Like:

        function optimize_database(){
        global $wpdb;
        $all_tables = $wpdb->get_results('SHOW TABLES',ARRAY_A);
        foreach($all_tables as $tables){
        $table = array_values($tables);
        $wpdb->query("OPTIMIZE TABLE ".$table[0]);
        }
        $query_revision = "DELETE FROM wp_posts WHERE post_type = 'revision'";
        $wpdb->query($query_revision);
        }

  • http://www.vooshthemes.com Chris Creed

    Thanks for this tutorial Jonathan. I’m looking to get into developing some WordPress plugins in the near future, so this will be a useful resource.

  • jeanv

    Hi! Great stuff! just a question, is that possible instead of calling the register_activation_hook() function to call add_action(‘wp’,'simple_optimization_cron_on’) and write all that in functions.php?Thanks!

    • http://www.curtismchale.ca curtismchale

      Not sure about the function question but any plugin code can also exist in the theme functions file and be theme code. The division should be made when there is functionality that you don’t want in every theme you build. So function specifically for a music site should most likely be a plugin since it is really only pertinent to music sites. At least that’s how I make the divisions in my theme development.

  • http://www.satya-weblog.com Satya Prakash

    I started thinking again when I will write my first plugin for wordpress. I am not leaving comfort zone. I have codes to use as a plugin in wordpress but just thinking from many months. huh!

  • http://www.pryde-design.co.uk Andrew Pryde

    Thanks a lot, this post is really well written and explains everything well. Kudos :)

    @Prydie

  • http://www.twitter.com/mamunabms Abdullah Al Mamun

    Thanks a lot for sharing, very good explanation.
    :-)

  • http://www.seo-smo.net/ Seo News

    Thanks for putting this wonderful post in such a descriptive manner. I always curious to the what are the best plugin for wordpress form every prospect.

  • http://zackhovatter.com Zack Hovatter

    Thanks! I was thinking about writing up a simple WordPress plugin to learn more about it. This helps a lot!

  • http://www.ecustom.ca/ Damon Bridges

    Excellent! I needed something like this to move me
    along.

  • http://icorbin.com Brandon Corbin

    It seems that 90% of the plugins are written using the spaghetti coding style – anyone have recommendations for a more “controlled” method of developing plugins?

    • http://createmy.com.au Dale Hurley

      I love these tuts to cover stuff I may of missed.

      I recently built a very complicated eCommerce solution for WP (not a shop). The client loves WordPress.

      I use a very simple MVC plugins to manage my files.

      First I setup a whole help of folders
      -controllers
      |—shortcodes
      -models
      -views
      |—template
      |—widgets
      -helpers
      -emailtemplates
      -css
      -js

      I have index.php, init.php, shortcodes.php, adminwindows.php. All this combines to make a nice manageable plugin.

  • http://wpcanyon.com Slobodan

    Thanks Jonathan.

    As i understood this is going to be a series of tutorials, right? Don’t forget to write one about plugin options (in the admin panel) :) I know how to create theme options but not really sure about plugin options, never actually needed to make some fancy plugin that requires options.

    • http://createmy.com.au Dale Hurley

      This is nice and simple

      add_action(‘admin_menu’, ‘my_plugin_menu’);

      function my_plugin_menu() {
      $name=’My Plugin Options’;//shown on the left admin panel
      $title=’My Plugin Options’;//shown as the title tags in the html head
      $userlevel= ‘administrator’;
      $link=’my-plugin-options’;
      $callback=’my_plugin_options’;

      add_menu_page($name, $title,$userlevel, $link, $callback);
      $parent=$link;
      $name=’Approve New’;
      $title=’Approve New’;
      $link=’approve-new’;
      $callback=’approve_new’;
      add_submenu_page($parent,$name, $title, $userlevel,$link,$callback);
      }

      function approve_new()
      {
      //….do or echo something
      }

      function my_plugin_options()
      {
      //do or echo something
      }

      //do not forget to use $wpdb!

  • http://www.curtismchale.ca curtismchale

    While that was an informative article I have a hard time seeing why this functionality should be a plugin and not just a theme level addition to functions.php. The reality is that you want to make these additions to each theme you build so why would you not just bake it in instead of adding it as a plugin.

    At the very least if you’re writing a plugin article I think it should contain functionality that is truly for plugins.

    • http://createmy.com.au Dale Hurley

      These functions in a plugin means you can use any theme.

  • Matt

    Great article, I just wish you would have explained more about the db optimization. Otherwise, really interesting stuff.

    • http://wildanr05.student.ipb.ac.id wildanr05

      +vote for this. need more explanation about db optimization. Thx for great article anyway :D

  • http://josephscott.org/ Joseph Scott

    A few thoughts while I read this:

    - I realize you were trying to come up with something for an example plugin to do, but I wouldn’t categorize the ‘rsd_link’ and ‘wlwmanifest_link’ items as “useless meta tags”. They do have a specific uses, blog clients make use of these. In the case of ‘wlwmanifest_link’ that’s for Windows Live Writer, but the RSD link is used by most (if not all) blog clients to find out the XML-RPC end point URL for the site.

    - The kses system in WP is designed to filter out bad/harmful markup, so describing ‘wp_filter_kses’ as an “unnecessary filter” would be dangerous at best. You could be opening yourself up to malicious code in the user description.

    - None of the function names in your plugin code are prefixed in any way. Adding a unique prefix helps avoid naming collisions. This is one reason why some plugins just use a class (there are other reasons, but making it easy to prefix is a good one too).

    - Optimize table will add some additional I/O as it clears out deleted rows. Exactly how big of impact that will have will vary, but certainly something worth keeping in mind. Instead of having it run daily at what every time the plugin was activated you could pick a time where the server is more likely to be servicing fewer requests, like 4am.

    • Joe

      that was exactly what I’ve just thought – these meta-tags aren’t useless at all – thanks for confirming :-)

  • http://www.deluxeblogtips.com Rilwis

    Nice tutorial. I love the way you optimize database. It’s very useful feature. Although WP users often optimize using a plugin or a tool like phpMyAdmin, this script is a much simpler solution for this. Very cool.

  • http://www.jgvisual.com JG Visual

    Great tutorial! Thank you. This was a great introduction to creating WordPress plugins.

  • http://www.unifiedarts.de Flowreen

    Nice tutorial, but it will be nice to have a screencast of it!

  • http://www.jordanwalker.net Jordan Walker

    Awesome article on ways to create a optimized plugin.

  • http://asturo.net Destiya Dian

    very nice tutorial, it will be useful for beginner like me.. :D

  • Paul

    Very helpful Tut.

    Thx.

  • Matt

    by the way, the tags function does not work. if an image is placed in the content (within the character limit specified) it throws a pretty big error.

    • http://fire-studios.com Jonathan Wolfe
      Author

      Yes, the plugin does assume for simplicity’s sake that there are no tags within the first 100 characters.

  • http://nerdynothings.com sean

    If there are no tags present we get this error:

    Warning: implode() [function.implode]: Bad arguments. in …..php on line 24;

    I tried wrapping the whole thing in an If statement, so:

    if($tags !== ”) {

    but that didnt work. any ideas?

    • http://viniciusalmeida.com.br Vinicius Almeida

      I solved it like this:

      $tag_string = implode(", ",$tag_array);

  • Tom

    Great article, thanks a lot.

    I am having one problem with the meta description code though. It was showing all html tags, and line breaks in my description. This could be because I have some other code where I allow such tags in my excerpts, so the excerpts aren’t completely bland.

    I managed to remove the html tags from the meta description by altering this line:

    $excerpt = strip_tags(substr($all_post_content->post_content, 0, 100)).’ [...]‘;

    As you can see, I added in strip_tags before substr. This worked on everything except the line breaks. Do you have any ideas how I can strip the line breaks too?

    • http://fire-studios.com Jonathan Wolfe
      Author

      You can add this line after the $excerpt line:

      $excerpt = str_replace(”, ”, $excerpt);

      That will remove any line breaks from the $excerpt variable.

      • Tom

        Thanks! That worked perfectly, but only if I did double quotes like this:

        $excerpt = str_replace(“”, “”, $excerpt);

      • Tom

        Damn nevermind, still not working.

      • Tom

        Figured it out..

        $excerpt = str_replace(” \ r \ n \ r \ n”,” “, $excerpt);

        I added spaces so it hopefully doesn’t strip what I’m trying to type.

  • http://www.tenaxtechnologies.com Development for IT Startups

    Very nice tutorial,
    Thanks.

  • http://campusano.net Victor Campusano

    A great tuto, thanks for the help! I may wish to know how much can i ask for a wordpress design?

    Regards!

  • http://createmy.com.au Dale Hurley

    One thing I would like to point out. The WP Cron is a Fake cron job. It executes when the first visitor after the escaped period visits the site.

    For example if it is daily at 4pm but there is no visits to 4:26pm then it is executed at 4:26pm and if the processing is intense it can leave the visitor waiting for a while.

    Dale

  • http://twitter.com/xrommelx xRommelx

    it show this error to me, anyone can help me ?

    Warning: implode() [function.implode]: Invalid arguments passed in C:\xampp\htdocs\Rommel\wp3\wp-content\plugins\xrx-simple-optimization\main.php on line 38

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘exert_to:description’ not found or invalid function name in C:\xampp\htdocs\Rommel\wp3\wp-includes\plugin.php on line 395

    line 38

    – $tag_string = implode(‘, ‘, $tag_array);

    • http://webipress.com Amaraa

      add this if($tags){ }

  • http://www.wd-60c9.com Thomas Miller

    Very nice, I’m a huge fan of WordPress and it’s great to see new really useful plugins getting released. Going to download and check it out, looks exactly like what I have been looking for for quite a time. So, thanks alot!

  • http://pinoyscreencast.com techie.biox

    very nice tutorial!

    is there a standard on creating a a full functional plugins on wordpress or what are the MUST need functions on creating a plugins. like in creating a theme theres a standard .php files to build the theme how about in creating plugins is there also a standard procedures..coz what I have notice here is like you have used some hooks to make the plugins more optimized? correct me if i’m wrong thanks.. is that a way of a good practice on creating a plugins ..

  • http://tomcatblog.info/ Giải Pháp Online Marketing

    Great tutorial! Thank you so much

  • http://www.marviorocha.com Marvio Rocha

    Hi Jonathan Wolfe,

    Great! I create, my fist plug for wordpress, wight your tutorials! These easy plug, help me at programmer station radio for wordpress!

    Sorry, my english, i from Brasil. ;-)

    thanks !

  • http://www.portalpower.com.br Tadeu

    Vamos testar parece ser muito bom!!

  • Luis Francisco

    one more done. THANKS!!

  • http://www.creativewebdesignsolutions.co.za Rudi Roux

    Great wordpress SEO plugins and customization. This post offered me alot of insight. I love WordPress and its SEO capabilities. Thanks

  • El garch

    Thanks u very much for this useful post,i still confused why uesed

    $all_post_content = wp_get_single_post($post->ID);
    $excerpt = substr($all_post_content->post_content, 0, 100).’ [...]‘;

    and we can get directly the post_content for the object $post, here is what it should be writing

    $excerpt = substr($post->post_content, 0, 100).’ [...]‘;

    I wanna you explain me why did u use the wp_get_single_post so can use simple the $post

    Thanks

  • http://vantraveler.com Evgeniy

    Thanks for tutorial.
    But why do not to implement these features via function.php?
    And it would be better to remove html tags from excerpt. Something like this:
    echo “\r\n”; // add meta tag to

  • http://www.jensenintelli.co.za Jensen Intelli

    WordPress continues to outshine joomla for website development in my opinion.

  • mark

    not working
    Warning: implode() [function.implode]: Invalid arguments passed in /home/a4711040/public_html/wp-content/plugins/simple_optimization/main.php on line 39

  • http://reza.barus-stuff.com reza

    I’m Sorry, can somebody teach me to make CMS using wordpress.. I dont know how to start… :(

  • http://academicwriterjobs.com ahmadshorif

    Yes, easily describe this plugin tutorial.
    But i am not sure, thats i will make plugin myself !

    Many thanks fro this tutorial

  • http://www.sacredbonding.com KAVESH

    I Loved Reading Reading your article… Will use this in one of my website surely…. Thanks a Lot… Would like to read more on optimization from you..

  • http://www.redbak.net.au Matt Ward

    Well written and informative article. Good job!

  • Piyush

    Hi,
    Thanks for this amazing tutorial. Can anyone explain me the execution time of this plugin? Means when it come into effect?

    Is this work only in case of single post page? And when $post->ID get value?

  • http://avorevolution.com G. Fresh

    Really am a fan of this tutorial, it was very helpful and as I am learning the basics of PHP this tut really contributed in understanding what every line of code in this plugin does. So thank you very much!

    I am trying to use this plugin, but after I was finished writing the main.php and activated the plugin I got the following warning:

    “The plugin generated 6 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.”

    And then, when I tried to update a URL in a simple box via admin side, I got the following warning:

    “Warning: Cannot modify header information – headers already sent by (output started at /home/avorevo/domains/avorevolution.com/public_html/wp-content/plugins/simple-optimization/main.php1) in /home/avorevo/domains/avorevolution.com/public_html/wp-includes/pluggable.php on line 881″

    I really want to use this plugin, but I can’t find out what I did wrong or why these warnings show up. Except the upper part at main.php, I tried with copying the code ‘The Final Code’ but with no avail. Also, I am recently using WP version 3.4.2 and deactivated the plugin until I know how to fix this. Does someone know what is going wrong and how to fix this? Thanks in advance

  • http://www.grumbleonline.com Jon Tetzlaff

    Really great tutorial. Looking to build a pretty complicated one shortly and this will help get a great start!

  • ajay malhotra

    i was finding this …thanx a lot for good tut..

  • Sitansu

    Awesome Plugin. Keep it up.