WordPress Plugin with jQuery
This course aims you to teach you how to code your own plugin on a WordPress website. We are going to learn together how to start, how to activate our plugin and how to change our content dynamically. For that purpose, we are going to use jQuery.
-
At the end of this course, i’ll provide you the entire plugin as files to use.
jQuery is an amazing framework made on top of JavaScript and released in 2006 by John Resign.
At its origins, jQuery was created to make JavaScript easier to execute. jQuery’s motto is “write less, do more” — and that’s exactly what it does; jQuery is a reusable piece of code that enables you to do more with JavaScript.
Why jQuery?
Most of developers that begin on WordPress have few notions of coding. jQuery is a very good alternative to start coding. Let me give you some reasons to use jQuery:
-
You don’t need to be experimented to start with jQuery,
-
Documentation is full of quick solutions to use,
-
Low restrictions on code (due also to JavaScript),
-
jQuery provides an amazing selector to select DOM elements,
-
You can write multiple tasks in one line,
-
You can handle every elements of your website,
-
It is Cross-Browser support…
You understand now why jQuery can be a powerful ally. There are many other reasons to use it but the main one: it is the best framework to start coding.
“jQuery takes common JavaScript tasks and wraps them into methods. Then, instead of writing out all that code by hand, developers can simply call these methods — jQuery takes care of the rest. These shortcuts allow users to write better code and be more productive. Many sites with JavaScript use jQuery, with many estimates putting the total at more than 50% of all websites.” Armina Mkhitaryan
So if you are looking for an efficient course to learn how to code your plugin with jQuery and WordPress, you are at the right place.
Introduction
A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress.
In this course, we are going to initialize our Wordpress instance.
Why We Make Plugins?
If there’s one cardinal rule in WordPress development, it’s this: Don’t touch WordPress core. This means that you don’t edit core WordPress files to add functionality to your site. This is because WordPress overwrites core files with each update. Any functionality you want to add or modify should be done using plugins.
WordPress plugins can be as simple or as complicated as you need them to be, depending on what you want to do. The simplest plugin is a single PHP file. The Hello Dolly plugin is an example of such a plugin. The plugin PHP file just needs a Plugin Header, a couple of PHP functions, and some hooks to attach your functions to.
This course is about getting basis of creating a WordPress plugin.
In this course, I am going to teach you how to display your plugin by tagging your shortcode inside your pages, posts, headers... The main idea is to create a function that is going to be called by your shortcode. This function has to be declared inside your Wordpress Plugin.
jQuery is an open source JavaScript library which is designed to provide easy client side scripting for HTML. It works on all major browsers.
Using jQuery, developers can perform certain actions right in the browser without reloading a page. Some of these actions include navigating a web page, selecting elements on a page to perform actions on them, call Ajax scripts, and handle events like what happens when a user clicks an element.
WordPress comes bundled with jQuery and some essential jQuery libraries. WordPress theme and plugin developers can easily call jQuery in their own plugins and themes to add their own jQuery scripts - but in our case, we are going to import it again to show you how to integrate libraries dynamically to your plugin.
jQuery is initially already loaded in WordPress. However, for the use of this course, we initialized it before as an imported script from a CDN. Let's now explore how I can trigger jQuery library from our app.js file.
About jQuery
jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.
The purpose of framework is to allow designers and developers to focus on building an unique feature for their web based projects rather than re-inventing by coding. Framework is specially created to help you boost the performance and efficiency of your web app development task.
Templating is when you create code that is pre-built for a specific purpose.
This can be done in virtually all coding languages and PHP is no exception.
Modular Code
For instance, you can create a template for the header section of your website and that header template can be included in your page templates.
This makes it easy to maintain your code so that in the event you need to change something in the header template, it’s only one file that you are actively refactoring and all the changes will be updated in all the files that include your header template.
This is making your code more modular and will benefit you in the long run.
In this course, we are working on creating our cookie management system. This course can be separated in two parts:
Implementing the logic,
Creating the actions.
First, we will add js-cookies library in order to manage our cookies.
Second, we will initiate our jQuery loading function to triggers our buttons.
Third, we will create conditions to manage cookies situations.
Finally, we will test our plugin and check that our cookies have been set or not.
Productivity Hacks to Get More Done in 2018
— 28 February 2017
- Facebook News Feed Eradicator (free chrome extension) Stay focused by removing your Facebook newsfeed and replacing it with an inspirational quote. Disable the tool anytime you want to see what friends are up to!
- Hide My Inbox (free chrome extension for Gmail) Stay focused by hiding your inbox. Click "show your inbox" at a scheduled time and batch processs everything one go.
- Habitica (free mobile + web app) Gamify your to do list. Treat your life like a game and earn gold goins for getting stuff done!