I found this example of a shortcode on the Internet:

function project_shortcode( $atts, $content = null ) {
    extract( shortcode_atts( array(
        'class' => '',
        'id' => '',
        ), $atts ) );

        return '<div id="' . $id . '" class="' . $class . '">' . $content . '</div>';

}
add_shortcode('button', 'project_shortcode');

This is the output I want:

<div class="container item">
    <div class="row">
        <div class="intro twelvecol">
            <div class="top-border"></div>
        </div>
        <div class="screenshot eightcol">
            <img src="https://wordpress.stackexchange.com/questions/37538/<?php bloginfo("template_url' ); ?>/images/studyatbest.png">
        </div>
        <div class="screenshot fourcol last">
            <h3>BEST LANGUAGE CENTER</h3>
            <p>BEST Language Center is an educational establishment in Taichung, Taiwan. I was asked to build and design a website they could use to offer classes, programs and display photos online.</p>
            <ul>
                <li>
                    <h4>ROLE</h4>
                    <p>Design, HTML/CSS, JavaScript</p>
                <li>
                    <h4>YEAR</h4>
                    <p>2010</p>
                </li>
                <li>
                    <h4>WEBSITE</h4>
                    <p><a href="http://studyatbest.com/">studyatbest.com</a></p>
                </li>
            </ul>
        </div>
    </div>
</div>

But I’m not sure how to do it so that I can return multiples lines in the shortcode (in order to keep the code clean). Any suggestions?

2 Answers
2

Don’t use output buffering. It is too slow and sometimes hard to debug. Use heredoc.

Example:

$output = <<<MYUNIQUENAME
    <div>$foo
      <p>Some $bar</p>
    </div>
MYUNIQUENAME;

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *