Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Creating Wordpress Custom Plugin

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 429
    Comment on it

    In this blog post i am explaining how to create a custom plugin which we can use in wordpress.

    For creating custom plugin first we have to create a file, here i am creating a plugin for a custom form type so i am naming the file as custom-form.php and then we have to create a folder naming custom-form-plugin within plugin folder in our wordpress theme and put custom-form.php file in it.

    Now we have to write the below code into our custom-form.php file. Below comment contain our Plugin information Author name and Author URL, Plugin version, Plugin URL.

    /**
    * Plugin Name: Form plugin
    * Plugin URI: http://memento.com/
    * Description: Custom form simple and easy to use.
    * Version: 1.0
    * Author: Akhil pandey
    * Author URI: http://akhilpandey.com/
    **/
    // Register the Form plugin

    The minimum information wordpress want to set our file as plugin is Plugin Name: Form plugin. The other information will be shown inside the Admin section under the Plugins area.

    With above code included in our file, save your code and explore to your WordPress admin dashboard. Click on Plugins which is on the left side of the admin dashboard, then we will see our plugin is accessible.

    Adding Our Plugin Code

    Now we want our custom plugin will contain a contact form for this purpose we have to put below code in our custom-form.php file.

    <?php
    function form_plugin(){?>
    <div class="quick-contact-widget widget two-third last">
       <div class="widget-last widget quick-contact">
       <h3>Quick Contact</h3>
       <form id="contact-form-example" class="contact-form" method="post" action="option.php" enctype="multipart/form-data">
                                <div class="usermessagea"></div>
                                <fieldset>
                                    <ul>
                                        <li class="text-field">
                                            <label for="name-example">
                                            <span class="label">Name</span>
                                            </label>
                                            <div class="input-prepend"><span class="add-on"><i class="icon-user"></i></span><input type="text" name="name" id="name-example" class="required" value="" /></div>
                                            <div class="msg-error"></div>
                                        </li>
                                        <li class="text-field">
                                            <label for="email-example">
                                            <span class="label">Email</span>
                                            </label>
                                            <div class="input-prepend"><span class="add-on"><i class="icon-envelope"></i></span><input type="text" name="email" id="email-example" class="required email-validate" value="" /></div>
                                            <div class="msg-error"></div>
                                        </li>
                                        <li class="textarea-field">
                                            <label for="message-example">
                                            <span class="label">Message</span>
                                            </label>
                                            <div class="input-prepend"><span class="add-on"><i class="icon-pencil"></i></span><textarea name="message" id="message-example" rows="8" cols="30" class="required"></textarea></div>
                                            <div class="msg-error"></div>
                                        </li>
                                        <li class="submit-button">
                                            <input type="text" name="yiw_bot" id="yiw_bot" />
                                            <input type="hidden" name="action" value="sendemail" id="action" />
                                            <input type="hidden" name="yiw_referer" value="#" />
                                            <input type="hidden" name="id_form" value="footer" />
                                            <input type="submit" name="yiw_sendemail" value="send message" class="sendmail alignright" />           
                                        </li>
                                    </ul>
                         </fieldset>
    </form>  
    
    <?php } 
    add_shortcode('form-plugin', 'form_plugin');
    ?>
    

    add_shortcode('form-plugin', 'form_plugin'); :- this function is creating shortcode for our plugin , by using this shortcode we can acess plugin where ever we want.

    Now we have to call this plugin in our page. For doing this we have to use below function.

     echo do_shortcode( '[form-plugin]' ); 

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: