How to selectively dequeue a script on individual post

Lot of plugins. Not sure what to do?? All of a sudden you may realise that you already have quite a lot of plugins on your website and probably some of those plugins are slowing your site down. That's the point of time you may decide to review your plugins but at that point it is very difficult to imagine the impact of deactivating a certain plugin. Here is a simple trick we can use to review our plugins and make sure atleast our important pages do not break. Idea The idea is to try and dequeue or remove a script on a page by page basis or post by post basic. Using this approach we are not deactivating the plugin on the entire site but we are just deactivating or removing it on just a single post or page. This way we can study the impact of removing the plugin on our most important pages/posts just so that we are sure it won't break our site and...
Read More

How to add custom checkout fields to WooCommerce order

Follow below steps to add custom checkout fields to WooCommerce. Scenario: We want to create a new address field named as territory. It will be a drop down field and will be used to decide the shipping cost. Create the new field/s on the checkout page [crayon-5996a71a6c22c822588665/] To create a similar field in shipping address, $fields array would need to be duplicated mentioning ['shipping'] instead of ['billing'] Now let us understand the parameters used in the above code Hook: Creating a new field uses woocommerce_checkout_fields hook type: Since this an drop down field the type of the field is select. If you want a mobile number field it could be a text field required: specify whether the field is compulsory or not. In our case we are calculating the shipping cost based on this field so it is compulsory. class:  form-row-wide: The new field will occupy the entire div width for the billing section form-row-first: The new field will appear in the first half area of the row (like the first name field) form-row-last:...
Read More

How to create wordpress options page

Creating Wordpress options page in Dashboard for your own plugin is quite simple. Generally it is used to set global preferences for your plugin which you want to let the users customise as per their requirement. We will create a settings screen by creating a class as that is the simplest way of creating your own options page for your custom plugin. It can be done in 5 simple steps Declare Class for the settings Page Add the page in the settings menu Register your settings Create the backend options Finally generate the options page Here is the entire code [crayon-5996a71a6d01f612048328/] Now we will discuss each function in detail First of all we have named our class as someCustomPluginSettings The constructor just calls the add_admin_menu function and initialises the settings registration [crayon-5996a71a6d02a950302359/] Below function creates the admin page. Here we need to provide Title of the settings page Capability (this decides who will get access to this page). manage_options means editors and above can access this page. Slug of the page [crayon-5996a71a6d02e696321999/] Below function registers the settings variables, description on the settings...
Read More

WordPress admin custom column sorting and filtering for custom post type

In WordPress Dashboard there are some default columns listed for any of your post types on the post listing page. We can sort our custom posts by Ascending or Descending order by just clicking these fields. However most of the times these fields are not enough. E.g. if we create a custom post for books then we may need columns to sort or filter books by Year of publication, Author, Category, etc So how do we create these extra columns for sorting and filtering Assumptions Custom Post Type: book Year,  Author and Language information is stored in custom meta fields for each book Se here are the steps Step 1: Define the custom colums [crayon-5996a71a6d4e3024668249/] Here we add two new columns to the admin panel of the custom post type book namely Publication Year and Author Step 2: Fill Data to the columns [crayon-5996a71a6d4eb963643322/] Here we are assigning data to the columns displayed in the custom post. Since the data is stored in the post meta we use get_post_meta function to get the data...
Read More

How to create custom post type template files in wordpress

Any wordpress theme comes with a single post, page and archive template. None of these templates may be suitable for you if are creating your own custom post for event, products, etc. In such cases we need to create our own templates There are 2 ways to create custom post type template files in wordpress Method 1: Create custom post type template files within your Child Theme folder Suppose your custom post type is event. You would create below files in your child theme directory. single-event.php archive-event.php Once the above files are created they will be automatically picked for your events single post and archive posts. So whatever your custom post type is, the template file names should be as named as below single-{post-type}.php archive-{post-type}.php Refer Wordpress Theme Handbook Advantages: It is very easy to create and modify your custom post type template files Disadvantages: The template files are not within your plugin. So if you want to install the plugin on some different website you need to remember to get the template files from the theme...
Read More

How to create extra widget/sidebar areas

Depending upon your theme you may have some predefined widget/sidebar areas like Left Sidebar, Right Sidebar. If you want to create a new sidebar area let's say for footer then you can add below code in your functions.php file Replace THEME_NAME with the name of your theme [crayon-5996a71a6e571820610511/] Finally add below code in the theme where the sidebar needs to appear [crayon-5996a71a6e57e150737877/]  ...
Read More

WordPress Security – Configuration / Installation

1. Wordpress security at the Configuration and installation level This section explains measures to be taken for achieving wordpress security while installing and configuring wordpress. 1.1 Change default table prefix Many published WordPress-specific SQL-injection attacks make the assumption that the tableprefix is wp, the default. Changing this can block at least some SQL injection attacks. 1.2 Securing wp-config.php Are you aware that wp-config.php can be stored one directory level above the WordPress installation? This is quite a simple task. Also, make sure that only you (and the web server) can read this file (it generally means a 400 or 440 permission). This file contains quite sensitive information like password, database user etc so it's very imp to protect this file 1.3 Disable File Editing through Wordpress Dashboard The WordPress Dashboard by default allows administrators to edit PHP files, such as plugin and theme files. This is often the first tool an attacker will use if able to login, since it allows code execution. WordPress has a constant to disable editing...
Read More
12