0

I want to have a structure like:

wp-content  
    |themes  
        |myTheme  
            |page.php  
            |contact.php  
            |break.php

In a page from WordPress admin, I want to add:

[break]
[contact]

And it will print the contents of break.php and contact.php. I've been looking at the codex for add_shortcode, but I don't understand how I'm supposed to define the php that is used as the contents of the shortcode.

  • 1
    While this is doable, this isn't how you should theme your pages. Use custom page templates instead. You'll also find the template hierarchy diagram incredibly useful – Tom J Nowell Apr 17 '16 at 0:07
  • And if there is a possible error in the code, there is a question how you will track that. Also if you plan to distribute the theme there is a security impact. Maybe this is why WordPress Rest API has been invented. – prosti Apr 17 '16 at 1:27
  • Custom page templates are something I have used in the past, however, there's pages that are essentially the same, but using a block that differs here and there. Doing custom templates would essentially be creating a new page layout because I want to use a simple block on this page but a different block on another. – o_O Apr 17 '16 at 1:29
0

You can write a wrap function for short code like that.

function simplest_shortcode_ever() {
    ob_start();
    ?>
        Your PHP Logic here
    <?php
    return ob_get_clean();
}
add_shortcode( 'simple_shortcode', 'simplest_shortcode_ever' );

And then use it[simple_shortcode]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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