Skip to content

Instantly share code, notes, and snippets.

@vmattila
Created September 10, 2012 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmattila/3693152 to your computer and use it in GitHub Desktop.
Save vmattila/3693152 to your computer and use it in GitHub Desktop.
WP Shortcode to show page contents (WPML enabled)
/**
* Usage: [wpml_page_content id=100]
* id attribute can be the id of any translation.
*/
function wpml_page_content_shortcode_handler( $atts, $content = null ) {
extract( shortcode_atts( array(
'id' => null,
), $atts ) );
// Here we'll hook with WPML functions and change the id to current language
if(function_exists('icl_object_id')) {
$id = icl_object_id($id,'page',true);
}
// Then fetching & outputting the content of the page
$post = get_post( $id );
return apply_filters('the_content', $post->post_content);
}
// Enables the shortcode
add_shortcode( 'wpml_page_content', 'wpml_page_content_shortcode_handler' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment