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? – yobddigi Dec 7 '15 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. – Dovid Levine Dec 8 '15 at 13:40
  • Have you tried using a shortcode using include(); ? – yobddigi Dec 8 '15 at 13:47

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 – Pieter Goosen Dec 9 '15 at 11:35

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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