I'm looking to extend a few plugins by adding custom shortcodes. These plugins create front-end pages, but I want to display that page content on another page. I figure there's an easy way to just take the entire php file that outputs the page data and wrap it in a function, but I'm not really sure how to start - where I should include the shortcode function and how I can get it to return the generated file. Thoughts?

(Eg: sabaidirectory create a directory dashboard page that solely outputs 'dashboard.php' to site.com/dashboard - I want that entire page to show up wherever I use [sabai-dashboard])

  • Do you know how to create shortcodes?
    – thebigtine
    Commented Dec 7, 2015 at 11:27
  • I know how to create one in functions.php (but thst includes pasting all the code there), not sure how to register one that uses the php from somewhere else. Commented Dec 8, 2015 at 13:40
  • Have you tried using a shortcode using include(); ?
    – thebigtine
    Commented Dec 8, 2015 at 13:47

1 Answer 1


Here is the code that you need to pull content from a wordpress page you will require the id number of the page and add it into the shortcode. [example page_id="21"][/example]

function example_shortcode( $atts, $content = null) {

    extract( shortcode_atts( array(
                'page_id' => ''
            ), $atts 
    // Will display our page content of the shortcode need a number of the page id

      $post = get_post($page_id); 
      $content = apply_filters('the_content', $post->post_content); 
      echo $content;  

add_shortcode('example', 'example_shortcode'); 

//[example page_id="page id number here"][/example]
  • Please use one account only Commented Dec 9, 2015 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.