how to make make shortcode of page/post in wordpress

Copy and paste this code in your function.php file
<?php
function digwp_includeContentShortcode($atts) {
  
  $thepostid = intval($atts[postidparam]);
  $output = '';

  query_posts("p=$thepostid&post_type=page");
  if (have_posts()) : while (have_posts()) : the_post();
    $output .= get_the_content($post->ID);
  endwhile; else:
    // failed, output nothing
  endif;
  wp_reset_query();

  return $output;

}

// USAGE
/*  In the post content, you can use 

[postPage_include postidparam="1234"]
"1234" would be the WordPress ID of the Page you are 

trying to include  */
add_shortcode("postPage_include", "digwp_includeContentShortcode");
?>
Method for use in post or page in back-end :-
[postPage_include postidparam="1234"]
"1234" would be the WordPress ID of the Page you are
Method for use in post or page in template :-
echo do_shortcode( '[postPage_include postidparam="1234"]' );

No comments:

Post a Comment