Pak Jiddat

Read: In the name of thy Lord Who createth, Createth man from a clot. Read: And thy Lord is the Most Bounteous, Who teacheth by the pen, Teacheth man that which he knew not. Nay, but verily man is rebellious That he thinketh himself independent!. Lo! unto thy Lord is the return. (Sura Alalaq 96:8)

Validate your WordPress blog using WordPress XML-RPC API, Php Tidy and Nu HTML Checker

Created On: 11 Apr, 2017: 12:28:53 - Tags : content management systems | website testing


WordPress is a very popular platform for hosting websites. Over 74 million websites are based on WordPress. WordPress is also increasingly being used to develop complex web based applications. There is a need for a testing system that allows testing applications and websites based on WordPress. Recently I had the opportunity of setting up a simple testing system for WordPress that validates WordPress blogs using the WordPress XML-RPC API, Php Tidy and the online Nu HTML Checker. I will describe my experience in this blog post. I will also briefly describe a couple of ways in which you can test server side code of your WordPress plugins.

What is the importance of Validating your website

Its a good idea to ensure that your WordPress blog conforms to W3C standards. The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. The W3C standard is recognized by all major search engines. Websites that conform to its standards can be understood by search engines and web browses more easily. Such websites have fewer performance problems and function more reliably across multiple devices. They are also sure to receive a higher ranking on the major search engines. WordPress websites usually support multiple plugins from different authors so its no small task to ensure that your blog conforms to W3C standards. I think its a good idea to use themes and plugins on your WordPress website that conform to W3C standards.

Validating your blog using Nu HTML Checker

The W3C validation website contains several tools that you can use to validate your website pages.  These tools include:
  1. Nu HTML Checker. It can checks HTML of any document. It supports HTML5
  2. Link Checker. It checks for broken links on your page
  3. RDF Validator. It checks and visualizes RDF documents
  4. Mobile Checker. It checks the mobile friendliness of your website
  5. Internationalization checker. It checks level of internationalization-friendliness of your website
  6. RSS feed validator. Validator for RSS and Atom feeds
  7. CSS Validator. Checks the CSS of your website
  8. Markup Validator. Checks the HTML or XHTML of your website
  9. Unicorn. Unified validator. HTML, CSS, Links and Mobile validator
The tool I used is called Nu HTML checker. It can be used to check any website for compliance with the new HTML5 standard. I created a php script that uses the WordPress XML-RPC API for getting list of all pages, posts, custom posts on my blog. The XML-RPC API is very useful and you can use it to easily get list of all pages on your blog. Once you have the list of pages, you can test each page against different W3C standards. For each post the script validates the post html using the PHP Tidy extension and the Nu HTML Checker. The PHP Tidy extension is a popular extension for php that allows repairing and formatting your html code. It supports HTML4 validation but does not support HTML5. If a post cannot be validated the test ends with an error. I ran this script with PhpUnit and added it to Jenkins Continuous Integration Server. I scheduled the script to run every day, so the script tests all pages automatically and sends me an email if any of the tests fail. Setting up projects in Jenkins is quite simple. You can refer to my earlier blog post titled Continuous integration and Project Management with Jenkins and Redmine for more information on how to add scripts to Jenkins.

Testing Server Side code of your plugins

Testing a WordPress website using PhpUnit is different from testing websites based on other platforms. WordPress has its own authentication system which prevents testing WordPress plugins and themes like normal php scripts. There are 2 main options for testing the server side code of your plugins:
  1. WP-CLI. WP-CLI is a command line interface to WordPress. It can be used along with PhpUnit to unit test your WordPress plugins. The WP-CLI website has some useful documentation on how to test WordPress plugins.
  2. Extend the WordPress XML-RPC interface inside your plugins. This method allows you to test your plugins using WordPress XML-RPC interface. Basically it allows you to call your test functions using WordPress XML-RPC interface.


WordPress is a very popular platform for websites. It is important to have a testing system in place that makes it easy to test WordPress based websites. Ensuring that your website conforms to W3C standards is very useful. It not only improves your SEO score but also ensures compatibility of your website across different devices and browsers. In my opinion it should be the first step in the optimization of any website.

Related Articles

  1. Creating custom themes for October CMS
  2. Developing WordPress plugins using Pak Php framework - Part 2
  3. Developing WordPress plugins using Pak Php framework - Part 1
  4. WordPress Deployment with Jenkins and Redmine
  5. Tuning WordPress performance using Varnish
  6. Improving WordPress Performance
  7. Creating your own WordPress themes and plugins
  8. WordPress for small and medium businesses
  9. Some excellant Wordpress Plugins