Created
September 10, 2012 19:20
-
-
Save vmattila/3693152 to your computer and use it in GitHub Desktop.
WP Shortcode to show page contents (WPML enabled)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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