Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WPML compatibility for WP-Buddy's Content After Posts Plugin
* Up to version 1.8.1 the plugin Content after Posts by WP-Buddy
* does not fully support WPML.
* Although 'caps' can be translated with WPML the translated 'caps'
* are not displayed if you switch languages.
* Add the follwoing function to your child themes functions.php to
* display the translated cap.
* Requirements:
* WordPress 4.9.4 or newer
* PHP 7.0 or newer
* Content after Posts by WP-Buddy up to version 1.8.1 (at the time of publishing this gist)
* Watch out the changelog for Content after Posts by WP-Buddy at
* Newer version may implement full WPML compatibility to make this patch not necessary any more
add_filter( 'wpbcap_content', 'maybe_get_translated_cap', 10, 4 );
function maybe_get_translated_cap( $cap_content, $cap_id, $cap_action, $cap_post ){
if (defined('ICL_LANGUAGE_CODE')) {
$type = get_post_type( $cap_id );
$t_id = icl_object_id( $cap_id, $type, true, ICL_LANGUAGE_CODE );
$t_cap = get_post( $t_id );
$cap_content = do_shortcode( $t_cap->post_content );
return $cap_content;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment