Adding a plugin textdomain / translation into wordpress

A plugin textdomain is required if you need to translate your own plugin in different langauges i.e. to internationalize the plugin.

Here are the required steps

Step 1: Decide the plugin textdomain name

e.g. my_plugin_textdomain

Step 2: Initialise the languages directory for the plugin textdomain

Add below code to your plugin

Create languages folder within your plugins directory.

Step 3: Create PO file for the languages

If you are creating a language translation for German then you would need to create a po file with below name

my_plugin_textdomain-de_DE.po

Download a sample PO file

Open the file in a suitable text editor and add the necessary translations in the file

Step 4: Create MO file

Once all the translations are added to the PO file open the file in Poeditor and just save the file. Poeditor will automatically create corresponding mo file. Upload both the files on your plugin languages folder

 

For the translation to show up for the corresponding words or phrases __(“sample text”) is to be used within the plugin code.

WordPress plugin – Create an explore topics page for your site/blog

Explore topics

Tags can be used quite effectively to show various topics you have covered on your site/blog.

Here is a plugin which lets you create an alphabetical listing of tags with search as you type filter as shown below

This plugin automatically lays all your tags in alphabetical order on a page and adds an ajax filter input box which allows to search as you type for a particular topic/tag.

Alphabetical listing of tags

Download the plugin from WordPress Plugin Repository

Features

  1. Search for topics as you type,
  2. Supports Multisite,
  3. Show your users the vast range of topics covered on your site,
  4. Help in visitor retention and reduce Bounce Rate,
  5. Simple and easy to configure

 

WordPress Plugin – Allows to selectively dequeue scripts/styles on each post

The plugin allows to dequeue or remove a script/style on a per post basis. It helps to improve performance of the site and you can make sure that atleast your important pages are optimised.

Download the plugin from WordPress Plugins Repository

The plugin is very simple. All you need to do is to edit a post which you wish to optimise and on the WPI Enqueue Manager meta box add the handles of the scripts or styles in bar (|) separated format to dequeue it from that post.

Detailed instructions on how to use this plugin

  1. Install and activate the plugin
  2. Upon activation, the plugin will show all the handles related to each enqueued styles/scripts on the source code of every page. Please see below screenshot
    script and style handles
  3. Just edit the post and add the scripts/styles in relevant boxes in bar (|) separated format to remove it from that post. Please see below screenshot

Enqueue Manager

 

WordPress plugin – Custom Admin columns for sorting and filtering

This plugin adds the capability to add custom columns to any post type to provide sorting and filtering of posts using those columns.

Download the plugin

Download the plugin from the wordpress plugin repository

Installation

To install the plugin follow below steps

  1. Upload the plugin files in wp-content/plugins folder (same as any other wordpress plugin)
  2. Activate the plugin

Configuration

Open the settings page “Custom Admin Columns for Sorting and Filtering”

As shown in the below screenshot add the extra fields and labels in comma separated format to the required post type

Settings screen for Admin custom columns

Custom columns will then appear on the respective post listing

Custom Weight column
Custom Weight column
Custom weight filter
Custom weight filter

 

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. On the options page select Browser Key

6. Add your domain name as shown in below screenshot

Screen Shot 2016-02-14 at 10.25.38 PM

7. Finally click the Create button which will generate the API Key

Step 2: Install the Google Maps plotter plugin

  1. Download the plugin files from WordPress plugins repository 
  2. Install and activate the plugin

Step 3: Generate XML file for the Google Map markers

Make sure you have the markers XML file ready.

XML markers file can also be dynamically created through php from your database or it could just be a static file in below format

Sample XML file for the markers

Read how to generate XML file dynamically – coming soon

Step 4: Display Google Map

Now just display the map on a page, post, custom post, widget, etc using below shortcode

Zoom => In above shortcode the initial zoom level is set to 2

html  => will display the marker popup text

Data attributes are separated with a bar (|)

Each data attribute has the data attribute matching to the XML file and the corresponding comma separated label

e.g. topic is the data attribute you wish to display while Topic is the label to it

Above html will display the popup as below after clicking the 1st Marker

Topic: Some Topic

Presenter: Mary

Date: 14-Feb-16

Telephone / Mobile:

Step 5: Stylize Google Maps Marker popup text

Now the last thing is to stylise the marker popup text

If you notice the source code for the marker. It is as below

So the label and the data associated with it can be easily styled using the IDs in your CSS

 

 

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

Google Custom Search
2. After creating your CSE you will get a search engine ID as shown below. Make a note of this ID.

Screen Shot 2016-01-25 at 12.10.01 PM
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.

Replace wordpress search with google custom search
Settings screen

5. Comment/Remove the code in searchform.php in your themes folder of probably header.php and add below code instead

This will create the search box.

 

 

 

 

Create wordpress plugin for custom PHP code

Often there is requirement to create your own PHP application and generally most people tend to install a plugin which allows to run PHP code snippets as it is much easier to do so.
Although this approach may seem ok it may not be ideal. Lot of times people use this approach because they do not know how to create plugin for the same in WordPress.

Actually it is much easier to create wordpress plugin than you think.
I understand it may take a bit longer to create a plugin than just writing a PHP code snippet. However the difference is not that big.

Creating your own WordPress plugin for your requirement works out better in the long run

  1. It allows you to deactivate as soon as you feel you do not need the code to run on your site
  2. You are in total control of the code.
  3. If the PHP plugin which allows you to run your PHP code snippets stops providing support or is no longer maintained then you need to find another plugin and move all your code to the other plugin. This means lot of your applications may break in the meantime.

Here is one simple solution to create wordpress plugin to run our small PHP code snippet.

  1. First of all create a folder in your plugin folder where the plugin files will reside e.g. my_php_code_snippet
  2. Create a main plugin file inside the folder called as plugin.php with below content
  3. Now create a file named my_php_code_snippet_class.php in the same folder with below contents

    If you want the snippet to be executed only for logged in users just add is_user_logged_in condition
  4. Activate the plugin
  5. Finally add the shortcode [PHP_CODE_SNIPPET_1] on the page on which you wish to execute the PHP code snippet

WordPress – Limit pages displayed in the parent page drop down

If you have lot of pages in your wordpress site then it becomes quite big problem selecting parent pages from a huge drop down.

There is a way to show only selected pages in the drop down as selectable parent pages.

This is never an issue for bloggers who have majority of their content in posts as there is no need to select parent post for a blog.

Download this plugin from WordPress plugin directory

Step 1: Create a custom field/Radio button to select if the page is to be listed in the drop down or not

 

Step 2: Save the option to the post custom field

 

Step 3: Limit pages listed in the page attributes drop down and quick edit parent page drown down

 

In Step 3 we are checking for pages which have custom field parent_dropdown set to 0 and excluding those pages from the page attributes drop down pages