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-59ebd652cc045585477051/] 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-59ebd652cc04f907000659/] 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-59ebd652cc054301542822/] 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-59ebd652cc47c049599602/] 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-59ebd652cc486290070960/] 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

Plot multiple places on Google Maps – WordPress plugin

Plot events, photos, places, etc on Google Maps using a simple Wordpress shortcode which is built using Google Maps API. Everything below can be achieved easily with a simple plugin, XML file to provide the markers and a configurable shortcode Plot Multiple Locations on a Map Marker Clustering (markerclusterer) Ability to click each marker to get more details i.e. through a Marker popup Marker's info popup details is customizable through shortcode and CSS Ability to set initial zoom level Step 1: Get an API Key for Google Maps API First of all we need an API key for Google Maps. You can get an API key from Google Developer Console Here are the steps to create an API Key 1. Visit Google Developer console Projects page and create a project as per your requirement 2. Go to API Manager and select the project created in above step 3. Enable Google Maps JavaScript API and Google Maps Embed API 4. Click the Credentials link 5. Click New Credentials and select API Key....
Read More

Replace wordpress search with Google Custom Search (CSE)

For better search results or due to integration with Adsense you many want to replace wordpress search with Google Custom Search (CSE) Below are the steps to follow using a simple wordpress plugin. [Download Plugin] 1. Register you site on Google Custom Search by filling a simple form as shown below 2. After creating your CSE you will get a search engine ID as shown below. Make a note of this ID. 3. Create a page to display the search results page and add [PW_ADD_GSEARCH_RESULTS] shortcode on this page. 4. Add the the URL of the search results page on the setting screen of the plugin. 5. Comment/Remove the code in searchform.php in your themes folder of probably header.php and add below code instead [crayon-59ebd652cce1a013547812/] This will create the search box.        ...
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-59ebd652cd684850975894/] Finally add below code in the theme where the sidebar needs to appear [crayon-59ebd652cd68c738674852/]  ...
Read More
12