DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. How to Convert a jQuery Plugin Into a WordPress Plugin

How to Convert a jQuery Plugin Into a WordPress Plugin

At DZone, there are two things we really love: devs and bloggers. Learn how to nurture both your inner dev and blogger in this article.

Gaurav Sharma user avatar by
Gaurav Sharma
·
Jul. 03, 17 · Tutorial
Like (2)
Save
Tweet
Share
7.26K Views

Join the DZone community and get the full member experience.

Join For Free

We’ve talked about how incredibly dominant WordPress can be as a web platform to publish your content. But, for all its features and functionality, some people still want more. While programmers and developers have been feverishly working to come up with every kind of plug-in and function imaginable to make WordPress easy and engaging to use, there are some jQuery plugins that simply do it better.

However, as plugins and API’s go, they are non-standalone software that implement functionalities into standalone software. If you didn't follow that right away, here is a succinct way of putting it: the person who made your jQuery plugin didn't make it for WordPress, and WordPress hasn’t updated their platform to seamlessly integrate the same kind of feature functionality you are looking to use.

That's why, today, we are going to be taking a look at the five simple steps you can take to convert a jQuery plugin into a WordPress plugin – so it seamlessly works within your WordPress site.

Get Your jQuery Plugin Organized

For the purposes of this article, we are going to assume that you have a jQuery plugin in mind that you want to convert into a WordPress plugin. Let's pretend it's a very slick way to sideswipe and navigate between website pages using your thumb and your ring finger. It's irresistible, easy, and unfortunately, only something that has been made using jQuery at this point.

Once you have the plugin downloaded, create a folder on your computer and title it with the name of the jQuery plugin. Next, take the uncompressed version of the jQuery plugin folder and place it as the subfolder in the folder just created. Lastly, remove all other files from the subfolder except for the “source” folder. This folder typically contains all the necessary scripts, images, and CSS the plugin needs to operate.

Move Your New Plugin Folder Hierarchy Into Your WordPress Folder Hierarchy

With your new parent folder selected, move all the files we just discussed into the root of your WordPress plugin folder. Simple enough, but very important.

Create an Original WordPress Plugin PHP File and Customize it as Necessary

PHP reigns supreme at this step in the process, and it’s the language to use throughout the creation of your original WordPress plugin.

Open a text editor program, and create a new file in your WordPress plugin folder with the title of the plugin. Except, this time, you are going to give it the extension “.php”.

Next, type in the following PHP tags:

<?php
?>

Copy and paste your plugin script between the tags. Adjust your CSS files based on the code as necessary. It should look something like this:

<?php

/*

Plugin Name: [NAME]

Plugin URL: http://www.jdmweb.com/resources/[NAME] //Url of your choice

Description: [NAME] for Wordpress

Version: 1.0

Author: [AUTHOR NAME]

Author URL: http://blogurl.com

License: Applicable License Info

*/

?>

Follow this up by adding in a wp_register_script. This registers the script to communicate seamlessly with WordPress. Additionally, use a wp_enqueue_script to link the jQuery script you are converting to your current WordPress theme. Finally, an add_action script can be used to line everything up and set the function to work with Wordpress.

// Add the scripts to the footer
function [NAME] js() {

    // Identify our javascript files

    wp_register_script(

        'jquery.[NAME]',

        WP_PLUGIN_URL.
        '/[NAME]/source/jquery.[NAME].pack.js',

        array('jquery'),

        "2.1.4",

        1);

    wp_register_script(

        'jquery.[NAME]custom',

        WP_PLUGIN_URL.
        '/[NAME]/source/[NAME].custom.js',

        array('jquery', 'jquery.[NAME]'),

        "1.0",

        1);

    // Then enqueue them

    wp_enqueue_script('jquery.[NAME]custom');

}

// Action our scripts

add_action('wp_enqueue_scripts', '[NAME]js');

The last thing you are going to want to do here is to specify a location URL so that WordPress knows where and when to activate the plugin.

Integrate Your New Plugin With WordPress

Right click on the folder containing your new plugin script and compress the folder. Navigate to that folder using the “Add New Plugins” sidebar feature on the WordPress admin page.

Install the zip file and make sure it’s activated.

Test and Repeat

That’s the short and fast way to convert your jQuery plugin into a WordPress plugin. Make sure you publish the plugin and view it in your browser to make sure everything works properly. Do this often to make sure everything stays intact.

Conclusion

There are many different features and functions that plugins serve, but it is a known and widely accepted idea that not all plugins were created equal. jQuery can empower some pretty slick user experiences, but that does not mean that WordPress users should be left out. Using the steps above you can convert your jQuery plugins into WordPress plugins easily.

WordPress JQuery Convert (command)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Express Hibernate Queries as Type-Safe Java Streams
  • Select ChatGPT From SQL? You Bet!
  • Mr. Over, the Engineer [Comic]
  • How Observability Is Redefining Developer Roles

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: