I have created this wordpress module for a shortcode and was wondering if there is any better way of doing it, to make it more light weight.
below is my code
<?php
add_shortcode( 'logo_section', function($atts) {
$output = '';
$atts = shortcode_atts( array(
// title
'section-title' => '',
'section-title-text' => '',
'image-source' => '',
'image-width' => '',
'image-height' => '',
'image-alt' => '',
// logos
'logo-1' => '','logo-1-image-source' => '','logo-1-alt' => '',
'logo-2' => '','logo-2-image-source' => '','logo-2-alt' => '',
'logo-3' => '','logo-3-image-source' => '','logo-3-alt' => '',
'logo-4' => '','logo-4-image-source' => '','logo-4-alt' => '',
'logo-5' => '','logo-5-image-source' => '','logo-5-alt' => '',
'logo-6' => '','logo-6-image-source' => '','logo-6-alt' => '',
'logo-7' => '','logo-1-image-source' => '','logo-7-alt' => '',
'logo-8' => '','logo-2-image-source' => '','logo-8-alt' => '',
'logo-9' => '','logo-3-image-source' => '','logo-9-alt' => '',
'logo-10' => '','logo-4-image-source' => '','logo-10-alt' => '',
'logo-11' => '','logo-5-image-source' => '','logo-11-alt' => '',
'logo-12' => '','logo-6-image-source' => '','logo-12-alt' => '',
), $atts );
$output .= '<div class="logo-section clearfix">';
$output .= '<div class="logo-section--inner clearfix">';
if ($atts['section-title'] == 'true') {
$output .= '<h2 class="heading--small heading--bold heading--uppercase heading--sans-serif heading--center">'. $atts['section-title-text'] .'</h2>';
} else {
$output .= '';
}
// first row
$output .= '<div class="logo-section--row clearfix">';
if ($atts['logo-1'] == 'true') {
$output .= '<img src="' . $atts['logo-1-image-source'] . '" alt="' . $atts['logo-1-alt'] . '" />';
} else {
$output .= '';
}
if ($atts['logo-2'] == 'true') {
$output .= '<img src="' . $atts['logo-2-image-source'] . '" alt="' . $atts['logo-2-alt'] . '" />';
}
if ($atts['logo-3'] == 'true') {
$output .= '<img src="' . $atts['logo-3-image-source'] . '" alt="' . $atts['logo-3-alt'] . '" />';
} else {
$output .= '';
}
if ($atts['logo-4'] == 'true') {
$output .= '<img src="' . $atts['logo-4-image-source'] . '" alt="' . $atts['logo-4-alt'] . '" />';
} else {
$output .= '';
}
if ($atts['logo-5'] == 'true') {
$output .= '<img src="' . $atts['logo-5-image-source'] . '" alt="' . $atts['logo-5-alt'] . '" />';
} else {
$output .= '';
}
if ($atts['logo-6'] == 'true') {
$output .= '<img src="' . $atts['logo-6-image-source'] . '" alt="' . $atts['logo-6-alt'] . '" />';
} else {
$output .= '';
}
$output .= '</div>';
// second row
$output .= '<div class="logo-section--row clearfix">';
if ($atts['logo-7'] == 'true') {
$output .= '<img src="' . $atts['logo-7-image-source'] . '" alt="' . $atts['logo-7-alt'] . '" />';
} else {
$output .= '';
}
if ($atts['logo-8'] == 'true') {
$output .= '<img src="' . $atts['logo-8-image-source'] . '" alt="' . $atts['logo-8-alt'] . '" />';
} else {
$output .= '';
}
if ($atts['logo-9'] == 'true') {
$output .= '<img src="' . $atts['logo-9-image-source'] . '" alt="' . $atts['logo-9-alt'] . '" />';
} else {
$output .= '';
}
if ($atts['logo-10'] == 'true') {
$output .= '<img src="' . $atts['logo-10-image-source'] . '" alt="' . $atts['logo-10-alt'] . '" />';
} else {
$output .= '';
}
if ($atts['logo-11'] == 'true') {
$output .= '<img src="' . $atts['logo-11-image-source'] . '" alt="' . $atts['logo-11-alt'] . '" />';
} else {
$output .= '';
}
if ($atts['logo-12'] == 'true') {
$output .= '<img src="' . $atts['logo-12-image-source'] . '" alt="' . $atts['logo-12-alt'] . '" />';
} else {
$output .= '';
}
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
return $output;
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire