Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-mail-logging domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /mnt/serverpilot1_srv/shawnhooper/apps/shawn-hooper/public/wp-includes/functions.php on line 6114
Add WPML Translations to WordPress REST API Response - Shawn Hooper Skip to content

Add WPML Translations to WordPress REST API Response

While integrating the WordPress REST API into a multilingual web application that my team is working on, we realized we needed a way to find out if there were translations of a specific page available, and if so, some basic details about it. The WordPress installation is running the WPML plugin to manage translations.  Google wasn’t quickly giving us any solutions to this, so I decided just to add the functionality myself.  Open Source for the win!

When querying the REST API, each post (or page, or custom post type) also returns the locale associated with that object, along with the Post ID, Permalink (URL), Post Title, and locale code for each available translation.

Today I’ve pulled that code out of our project, and released it as an isolated plugin.

Interested? For now, you can download the WPML REST API plugin from GitHub.  It’s been submitted to the WordPress plugin repository, and is awaiting approval from the wonderful volunteers there.

As always, bug reports and pull requests are welcome.

2 Comments

  1. max max

    hi Shawn,
    i’ve downloaded WPML REST API from github and loaded it up in plugins, but it does not activate. no errors, just stays inactive.
    WP version is 4.7.5
    i read it’s been tested up to 4.7.2, have you tested it on 4.7.5? any hint on what the problem may be?
    thanks for any help,
    max

  2. max max

    … just to add some more info, the server runs PHP Version 5.3.3

    thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.