Custom Taxonomy URL in WordPress

When you create a custom post type and a new taxonomy for that post type, you will notice that the URLs for the taxonomy values do not follow the same format as the blog category taxonomy value URLs.

For example, if one of the category values for your blog post is “mobile”, the URL would be:

Now, if you have a custom post type called “portfolio” and a category taxonomy where one of the taxonomy values is “mobile,” then the URL would be:

Instead of

And sometimes, the custom post itself will be under “-category” URL like following:

Now, this wasn’t that big of a deal until I realized that this would kinda mess up the analytics.  For example, what if you wanted to see which post type had the most traffic in Google Analytics and you were looking at Page path level 1, i.e., the first subdirectory in the request URI?  It would exclude all the data that went to /portfolio-category/* when looking at the traffic for the portfolio post type.

If you Google this, you may find a few articles presenting potential solutions.  But if all you really need is for the analytics purpose, then there is a quick way to resolve this in Google Analytics.

You can add a “Search and Replace” filter to your view.

Filter Name: any name
Filter Type: Custom -> Search and Reaplce
Filter Field: Request URI
Search String: /portfolio-category/mobile/
Replace String: /portfolio/category/mobile/

Here is a screenshot:

Using Filter to fix WordPress custom taxonomy URL

This will fix any data issues created by the weird URLs.

MarkLogic WordPress Plugin

If you want to provide advanced search to your WordPress website, you can use MarkLogic WordPress plugin to replace the default search with MarkLogic search.

The plugin integrates with MarkLogic database, sending all your content – pages, posts, and custom content as well – from WordPress website to a MarkLogic server.  Then when a search is made on your site, it will send the query to MarkLogic server, retrieve search results, and display them on the search results page.  It’s all done through MarkLogic’s REST application which is extremely easy to set up and configure.  Then we used MarkLogic REST API PHP Library to facilitate the communication between WordPress and MarkLogic REST endpoint.

If you have a small WordPress website with less than 100 pages, then this plugin may be an overkill for you.  You may find this plugin useful in one of following cases:

  • You manage a WordPress website with hundreds or thousands of pages and want to provide fast search
  • You manage multiple, related WorPress websites – such as multiple websites for a single organization – and want to provide one search against all databases
  • You want to provide advanced search with features such as facets/taxonomies, indexed search

Below shows data structure of a sample blog post before it is ingested into MarkLogic.  Notice that the category and tag information is included as well.

I will go into details of the plugin in upcoming blog posts.  I just wanted to introduce the plugin at a high-level .

Stay tuned!

How to Rank Higher on Local Search

I am currently helping a small business get better found online and in local searches.  They specialize in jewelry and watch repair and are located in Chantilly, Virginia.  When I did a search on “jewelry repair in Chantilly” or “watch repair in Chantilly” on Google, I could not find their business at all!  Within two weeks, I was able to get them on a second page of Google search result with a few keywords.  My plan is to get them on the first page.

In this blog post, I thought I would share with you what I did to get on the second page of Google search results and what I plan to do to get on the first page.

Google My Business

The first step I did was to register the business on Google My Business.  This has many benefits.  It will let your business show on Google Maps when customers search for keywords relating to your business.  It will also start showing your business in Google search results if you are not already indexed by Google.  For more thorough listing of why you should register your business, check out their benefits page.  Keep in mind that Google will need to verify your business – this can take one to two weeks.  Once you register, they will send a letter containing pin number which you will use to complete the registration.


How will your customers find you on search?  They will likely use some words followed by city or state.  For example, a user looking for a strawberry farm to take his/her family this weekend will likely use one of following keywords:  “strawberry picking in va”, “strawberry picking in northern va”, or “strawberry picking in haymarket.”  A good way to see what words are available is to go to Google and check out their suggestions.

Find local SEO keywords

But do not limit yourself to what Google suggests.  Try to put yourself in customer’s shoes and think hard on how they would find you.  Maybe they will use “strawberry farm in virginia” or “pick strawberry in virginia.”  So when you write content for your website, try to have a good mix of different variations of a target keyword.  The important part is adding location to the keyword.

For the jewelry repair business, following are some of keywords I targeted:

  • “jewelry repair in Chantilly”
  • “jewelry repair chantilly va”
  • “jewelry repair in South Riding”
  • “watch repair in Chantilly”
  • “watch repair in South Riding”

The owner wanted to target both Chantilly and South Riding, a nearby town, so the list got slightly longer.

Website Optimization

Once you have identified keywords for local search, make sure those keywords are used on your website including URL, page title, page description, page header H1, image title and alt tag, and the content.

For the content, you need to be creative and come up with content that accurately describes the business, and their products and services.  I’ve read that Google likes websites that provide more comprehensive information on certain products, services, or topics.  So be as thorough as possible thinking how the content would be helpful to your customers.

By this point, and waiting for about two weeks, I was able to get the business on the second page of Google search result page with some of the above keywords.  Now, that wasn’t too hard so far, right?

Now, to get to the first page, it will require a lot more work and creativity.

Local Directory

If you didn’t know, there are a number of local directory websites out there including YellowPage, Yelp, Foursquare, and Factual.  If I really wanted to get a business on the first page of Google, I would list the business on all local directory websites available and that is what I plan to do with the jewelry repair business.

Chances are that some of those sites may already have your business information, but with outdated phone number or address.  In addition to having your business listed on those sites, you also need to ensure that the information is correct and consistent throughout.  Google will rank your business higher when it aggregates information from all those sites and the data is consistent.

So following are some of the local directory sites I have used and some new ones I found recently:

  • Foursquare
  • Yelp
  • Localaze
  • Factual
  • Axion
  • Infogroup
  • YellowPage
  • SuperPage
  • Neustar
Moz Local
Moz Local

Now, if you want to speed up, you can use services like Moz Local where you pay about $84 per year and it will ensure that your business is listed on all above and in a consistent manner.  I have used it before to a great success.

Press Release

If you have any news worthy stories such as forming a partnership with another business, hosting a special event, or maybe launching of a new e-commerce website, you should work with a PR consultant to write and publish a press release.  This allows other news outlets or bloggers to pick up the story and if the story is interesting enough, they will write about it in news or blog article.  I helped publish three press releases for one of businesses I helped and they are ranking second and third on Google for their target keywords. (of course, there is a lot of other work that went in too)

Link Building

Link BuildingIn my opinion, this is the hardest part of SEO and requires you to be super creative.  The goal here is to get other sites to create links to your website.  But how do you do that?  One of the most effective ways is guest blogging.  If you have a new product, you can reach out to bloggers in your industry, send them some samples, and ask them to write about the product.  If you are part of a local chamber, definitely reach out to the chamber and have them list your site on their site.  For a popular wedding venue I helped, we were able to get their site listed on a local tourism website by reaching out to local Tourism and Economic Development office as well as on the official Virginia State Tourism website,

There are many ways to build inbound links to your site.  You just have to be creative and understand the inner workings of your industry to reach out to the right people.

In addition to above, I will also revisit the business website frequently to add more content and refine them.

In near future, I will follow up with another blog article detailing the result achieved. Stay tuned!

Online Marketing for Small Business

I have helped many small businesses with their online marketing for quite some time.  In doing so, I noticed that I was following a general pattern – build a website, create traffic, capture lead information, and make tweaks & optimize website to generate more traffic and more leads.  Following this framework, I was able to help many businesses become successful with their online marketing – consistently.

It took a while, but I finally put myself together and wrote this article hoping that this framework will be helpful to others just starting out with online marketing for their business.  In explaining each process in framework, I stayed at very high-level and left out a lot of details.  My plan is to cover they in more detail in later blog posts.

If yo have any questions, please feel free to add comment below or send me an email at

Online Marketing Framework
Small Business Online Marketing Framework

Build Your Online Presence

The very first step in online marketing is building your online presence.  You should start with a website, then target popular social media sites.

These days, sites like Wix and Weebly provide easy drag-n-drop features that make building a website very easy.  If you’ve never had a website for your business, that is a great place to start.   More advanced option is where you can create a website with WordPress and have it hosted there.  All those services are free – but if you want your own domain name, which I highly recommend, then you pay small fees – anywhere from $5 to $25 per month.

In addition to website, you should also build presence on social media sites such as Facebook, Yelp, Google, Twitter, Pinterest, and Instagram, etc.  They all have unique user base and where you should focus on more depends on what industry you are in.  At minimum, I always recommend Facebook, Yelp, and Google.

Generate Traffic to Your Site

So now that you have a website, how do you get more people to come to your site?  That is a million dollar question.  There is this whole SEO industry where companies are paying a lot of money to get Google traffic to their site.  But if you are just starting online marketing and do not want to spend much money, following are some options:

  • Submit your site to Google via Google Webmaster
  • Create interesting content around your industry and let Google find you (SEO)
  • Submit your site to local business directories such as Foursquare, Yellowpages, Superpages
  • Find free business directories targeting your specific industry
  • Write blogs
  • Come up with promotional and sale events for your products and services and share on social media

This is really at a high-level and I will go into more details in a later blog post.

Convert Website Visitors to Leads

Now that you are getting some traffic to your site, what should you do next?  Do you want your website visitors to browse your site and just leave?  It’d be like customers coming to your store, just looking around, and leaving.  You wouldn’t want that, right?  You want them to either make purchase, or ask you questions about your products.  Same applies to your website – you want site visitors to turn into a qualified lead who will eventually purchase your products or services.  You can do that in number of ways.

The most simple method is having a form on your site and let site visitors fill out the form to learn more about your business, products, or services.  In this way, you capture their name and email, and you can later follow up with additional information which will eventually turn into sales.

Some other methods are:

  • Making a purchase (for e-commerce website)
  • Subscribing to a newsletter or blog
  • Downloading interesting article
  • Visiting a particular page

The key here is to capture name and email, and building a database of leads over period of time.

Measure Traffic & Optimize Website

The final phase in online marketing for small business is measuring your web traffic and optimizing your site so that you will get more qualified leads from the traffic.

Google Analytics is a free traffic measuring tool from Google and I use it for every websites I build and manage.  The tool gives you insights to who your visitors are, how they come to your site, what content they engage with, how they convert from visitor to lead, etc.

With the information you get from Google Analytics, you can sort of figure out where to spend extra resources – i.e. we saw more traffic coming from facebook so we will increase marketing on facebook – and how to optimize your website to get more qualified leads – i.e. we saw more traffic coming from mobile devices but they spent only 15 seconds on average as compared to 40 seconds for desktop traffic.

You can also build a landing page and conduct A/B testing – these are more advanced topics and may not be suitable for small businesses just starting out with online marketing.

I hope that this article has been helpful to you.  The framework I laid out here is what I use for all businesses that I help and please feel free to apply it to your business.

Syncing a Fork

At work, we work with an agency who provides website development services. They own and maintain the repository on github and we only have read access to it. So in order for us to make changes, we have to fork the repository, make changes, and send pull requests.

However, because developers at the agency work on the site everyday, our forks are not always up-to-date with the original repository. Then when we need to make changes, we have to make sure that we have the latest changes in our forked projects before sending pull requests. So here is a set of commands you can run to make your forked repo up-to-date with the original repo.

First, fetch all branches and commits from the upstream (original) repository.

Check out your fork’s local master

Then merge the changes from upstream to your local master

At this point, you have all the latest changes from original repo on your local machine. Next we sync up the changes from your local machine to your fork.

That’s it!

Enable Distance Filtering in Drupal Services

When developing mobile apps, location is one of core components that nearly all mobile apps are developed with.  However, when it comes to building mobile apps with Drupal, working with location can be challenging.  There are number of geo-related modules and discussions on enabling location by working with Views.  But in our case, we decided not to use Views, but just with the Services modules, to provide the maximum performance to mobile apps.

So in this post, I will show you how we enabled distance filtering/sorting in Drupal so that the XML/JSON data you get through Services module is filtered or sorted based on locations or latitude/longitude data.

For this, we used following tools/modules:

  • Postgresql database
  • PostGIS extension
  • Services module
  • AddressField module
  • Geocoder & Geofield modules

Postgresql – we use Postgresql instead of MySQL because working with locations is much easier and faster by using PostGIS extension.  Yes, it “is” possible to enable locations with MySQL, but for this exercise, we will use Postgresql and PostGIS combination.

1. Install PostGIS extension

There are numerous websites and pages that show you how to install the PostGIS extension so I won’t cover that here.

2. Install Services, AddressField, Geocoder, Geofield modules

These are all standard Drupal contributed modules that are fairly stable.  If you’ve been using Drupal, then these modules should be familiar to you.  If not, you can easily install them using drush:

3. Create a new field for storing address

Now that we have everything installed, we will go ahead and create a new content type and field to store location information.

We will create a new content type called “Business” and two fields: Address (postal address) and Geodata (geofield) for storing location information such as Well Known Byte (WKB), latitude and longigude. You have to set up Geodata field as “automatically encode from another field” and choose the address field.

Location modules in Drupal

Now, if we look at the database table that holds the field_geodata information, there are three columns that we are interested in and will be using for our exercise: field_geodata_geom, field_geodata_lat, and field_geodata_lon.

Underlying table for Geofield

Your table at this point would be empty. I took above screenshot after adding some sample businesses.

4. Create a custom REST endpoint

For our purpose, we will be exporting businesses from a Drupal site to XML/JSON using the Services module which will be consumed by client apps such as mobile applications. We will create one index function that will retrieve all businesses.

First, create your own module. Then, create a custom REST endpoint using using MODULE_services_resources() to create your own endpoint.  I called my module “isaac”:

There are some great tutorials on how to create custom REST endpoint:

We will review three PostGIS functions used in above code:

  • ST_Distance – Given two geometry points, this function returns distance between two points in spatial ref units
  • ST_MakePoint – Given latitude and longitude, this function returns a point geometry that can be used in ST_Distance and other PostGIS functions
  • ST_GeomFromWKB – Creates a geometry instance from a Well-Known Binary geometry representation (WKB)

So what’s happening here is that ST_Distance() will return distance values that we can use for filtering or sorting in our code. ST_Distance() takes two geometry points – user’s location and business location.

For user’s location, we pass in lat/long coordinates through URL and convert it to geometry point using ST_MakePoint() function.

For business location, we can do same with values from field_geodata_lat and field_geodata_lon columns or we can use field_geodata_geom value. Geofield module stores Well-Known Binary (WKB) data in that column and we use ST_GeomFromWKB() function to convert that into a geometry point.


We will test with following four businesses – also indicated in red marker on below map:

  1. Atlantic Coast Mortgage LLC – 4100 Monument Corner Dr, Fairfax, VA 22030
  2. Silver Spoon Caterers – 12450 Fair Lakes Cir, Fairfax, VA 22033
  3. Allegra Fairfax – 2812 Merrilee Dr, Fairfax, VA 22031
  4. Capitol Financial Partners – 1593 Spring Hill Road, Vienna, VA 22182

The user will be in Fairfax – indicated in blue marker on the map.

Build mobile apps with Drupal

We then call the endpoint we created above with latitude/longitude of user’s location (blue marker) as parameters:

We then get following results:

As you can see from the distance values, the four businesses were retrieved based on lat/long location data sent in as parameters. They are sorted by distance from shortest to farthest.

As mentioned above, ST_Distance() function will return distance in spatial ref units. If you want it in meters, you can use ST_Distance_Sphere() in place of ST_Distance(). Make sure to check out the PostGIS documentation if you want to see what other functions are avaialble.


So in this post, I wanted to share my proof of concept that location feature can be made available in Drupal when it’s being used as a mobile backend – that is, without using Views.

We only passed in latitude and longitude to our custom REST endpoint but we can also add “limit” and “offset” param/value pairs to enable paging so that you get only 20-30 businesses at a time if there are a lot of businesses.

Increase Website Conversion Rate

Recently, we had to re-evaluate our online strategy when one of our websites was not performing well – not generating the leads that we were looking for. While there can be a number of different reasons for low conversion rate, Google Analytics provides tools to help you visualize how visitors arrive at your goal once they are on your website. Goals can be anywhere from filling out a form to downloading a PDF file.

Check out the following site to learn about how you can you use funneling in Google Analytics. It will help you identify where the site visitors are dropping off and where you can make improvement.

The Google Analytics Conversion Funnel Survival Guide

Improving your backend experience on Drupal

For one of my projects I’m actively working on at the moment, I spend a lot of time on the backend of a drupal website.  I often find myself looking for ways to make the backend processes more efficient, looking for good modules or ways to make the drupal website faster.  A few days ago, I came across a presentation given at the Drupalcon in Portland last year.  The speaker provides many useful tips on making the drupal backend experience better and I thought it was very helpful for me at least.  I highly recommend this presentation to those that manage drupal websites.

Download: Secrets to Awesomizing® Your Editor’s Back-end Drupal Experience

Original page: link

Have fun!