Miklas Njor

Jetpack related posts and qTranslate-X fix

Problem:
I had some trouble getting Jetpack's Related Posts to play nice with qTranslate-X. The issue I had, was that Jetpacks Related Posts did not translate the post's headlines and link title tags, and since this site is mulitlingual and most of the articles are both in Danish and English, this is a big problem.

 Obviously with the many settings in the eco system, the fault could lie elsewhere, however a lot of switching off of plugins and settings, clearing caches and under the hood etc., led me to believe, that the fault is with . The fix is pretty simple, except it will be overridden next I update the plugin, so I have notified the developers of Jetpack.

In line 3, in the code snippet below, the original code is

return wp_strip_all_tags( $post_title );

which means that the posts title is returned to the system and stripped of all tags (syntax). The title is however not internationalised, in the sense that the system doesn't account for any translations of the post title string.

The solution
The solution is to add __() around the $post_title so the line becomes

return wp_strip_all_tags( __($post_title) );

The place to make changes is: wp-content/plugins/jetpack/modules/related-posts/jetpack-related-posts.php on line 697 (in version: 20150408 of the plugin)

protected function _get_title( $post_title, $post_content ) {
        if ( ! ( $post_title ) ) {
            return wp_strip_all_tags(  __( $post_title )  );
        }

        $post_title = wp_trim_words( wp_strip_all_tags( strip_shortcodes( $post_content ) ), 5, '…' );
        if ( ! empty( $post_title ) ) {
            return $post_title;
        }

        return __( 'Untitled Post', 'jetpack' );
    }
Exit mobile version