The Goal
Creating a simple plugin that replace <!--ltme=COLOR--> with BIG and colored "Less Talk, More Example" words. Take a look at images below.
The Process
- Open your text editor then create a new file.
- Copy and paste code below.
<?php /* Plugin Name: LTME Plugin URI: http://www.less-talk-more-example/ Description: Simple plugin to subtitude the <!--ltme=COLOR--> string BIG "Less Talk, More Example" string. Author: Rio Astamal Version: 1.0 Author URI: http://www.rioastamal.net/ */ // print some CSS to the header function ltme_head() { echo ' <!-- start ltme --> <style type="text/css"> .ltme { padding: 20px 12px; font-size: 2em; font-weight:bold; border: 1px solid #ccc; background: #E5E5E5; } </style> <!-- end ltme --> '; } // function to replace the <!--ltme=COLOR--> string function ltme_replace($post_content) { $replacement = '<div class="ltme" style="color: $1">Less Talk, More Example</div>'; $post_content = preg_replace('/<!--ltme=([a-zA-Z#0-6]+)-->/', $replacement, $post_content); // if we enter using visual mode, wordpress intrepet the <!-- string differently $post_content = preg_replace('/<!–ltme=([a-zA-Z#0-6]+)–>/', $replacement, $post_content); return $post_content; } // Register our hooks add_action('wp_head', 'ltme_head'); add_filter('the_content', 'ltme_replace'); ?> - Save the file to path wp-content/plugins/ltme.php
- Now, activate the LTME plugin
- Write some content that include LTME special tag.
Hello LTME Reader, This is example of simple plugin creation on wordpress. Print LTME with green color <!--ltme=green--> print LTME with #c60000 color <!--ltme=#c60000--> - Publish your post, the result should look like this
- Congratulation for your first Wordpress plugin :)
Wordpress Version
Tested on Wordpress version 2.8.4 but should work for all version.
Download the Code
Having trouble copy or paste the code? Download the file here:ltme-plugin.zip via ziddu.com.
Size: 0.72kb
MD5 Checksum: f8898209768ed7524afa4c59eefc82ee




0 komentar:
Post a Comment