Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Output Buffer Example
<?php
/**
* Create the hero markup based on arguments.
*
* @param array $args The hero arguments
* @return string The hero markup
* @author Greg Rickaby
*/
function wds_client_get_hero( $args = array() ) {
// Set hero defaults.
$defaults = array(
'background_id' => '',
'title_id' => '',
'paragraph_text' => '',
);
// Parse args.
$args = wp_parse_args( $args, $defaults );
// Start hero markup.
ob_start(); ?>
<div class="savor-area image-as-background" style="background-image: url( <?php echo wp_get_attachment_url( $args['background_id'] ); ?> );" role="dialog" aria-labelledby="hero-title" aria-describedby="hero-description">
<div class="savor-content-area">
<div class="savor-title-area">
<img class="savor-title" src="<?php echo wp_get_attachment_url( $args['title_id'] ); ?>" alt="<?php esc_html_e( 'Weekly Savor', 'centralmarket' ); ?>">
</div>
<p class="savor-paragraph"><?php echo wp_kses_post( $args['paragraph_text'] ); ?></p>
<a class="button savor-button" href="#" title="<?php esc_attr_e( 'Select Your Store', 'centralmarket' ); ?>"><?php esc_html_e( 'Select Your Store', 'centralmarket' ); ?></a>
</div><!-- .savor-content -->
</div><!-- .savor-area -->
<?php
// Return hero markup.
return ob_get_clean();
}
<?php
/**
* INCORRECT!
*/
function wds_client_get_hero( $args = array() ) {
// Set hero defaults.
$defaults = array(
'background_id' => '',
'title_id' => '',
'paragraph_text' => '',
);
// Parse args.
$args = wp_parse_args( $args, $defaults );
// Start hero markup.
$output = '';
$output .= '<div class="savor-area image-as-background" style="background-image: url(' . wp_get_attachment_url( $args['background_id'] ) . ');" role="dialog" aria-labelledby="hero-title" aria-describedby="hero-description">';
$output .= '<div class="savor-content-area">';
$output .= '<div class="savor-title-area">';
$output .= '<img class="savor-title" src="' . wp_get_attachment_url( $args['title_id'] ) . '" alt="' . esc_html__( 'Weekly Savor', 'centralmarket' ) . '">';
$output .= '</div>';
$output .= '<p class="savor-paragraph">' . wp_kses_post( $args['paragraph_text'] ) . '</p>';
$output .= '<a class="button savor-button" href="#" title="' . esc_attr__( 'Select Your Store', 'centralmarket' ) . '">' . esc_html__( 'Select Your Store', 'centralmarket' ) . '</a>';
$output .= '</div><!-- .savor-content -->';
$output .= '</div><!-- .savor-area -->';
// Return hero markup.
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.