I want to create a shortcode for one of the content form theme.
My template's content:
<section id="standing" style="background-image: url('<?php echo (get_option('pixieclash-standings-background') && get_option('pixieclash-standings-background') != null) ? esc_url(get_option('pixieclash-standings-background')) : get_stylesheet_directory_uri() . '/images/standings-bg.jpg' ?>');">
<div class="container">
<?php
$headTxt = get_option('pixieclash-standings-section-heading-top');
$bottomText = get_option('pixieclash-standings-section-heading-bottom');
?>
<?php if(!empty($headTxt) || !empty($bottomText)): ?>
<article class="head">
<?php if(!empty($headTxt)): ?>
<h4><?php echo esc_attr($headTxt); ?></h4>
<?php endif; ?>
<?php if(!empty($bottomText)): ?>
<h3><?php echo esc_attr($bottomText); ?></h3>
<?php endif; ?>
</article>
<?php endif; ?>
<?php
$groups = pixieclash_standings_groups();
if(!empty($groups)):
$i = 1;
$onlyOne = count($groups) > 1 ? '' : 'onlyOne';
foreach($groups as $group):
$competitors = pixieclash_standings($group['id']);
?>
<article class="table <?php echo ($i % 2 != 0) ? 'first' : 'second' ?> <?php echo $onlyOne ?>">
<h5 class="group-name"><?php esc_html_e('Group', 'pixieclash') ?> <?php echo esc_attr($group['name']) ?></h5>
<table class="table-body">
<thead>
<tr>
<th><?php esc_html_e('Competitor', 'pixieclash') ?></th>
<th rel="match<?php echo esc_attr($group['id']) ?>"><?php esc_html_e('M', 'pixieclash') ?></th>
<th rel="win<?php echo esc_attr($group['id']) ?>"><?php esc_html_e('W', 'pixieclash') ?></th>
<th rel="till<?php echo esc_attr($group['id']) ?>"><?php esc_html_e('T', 'pixieclash') ?></th>
<th rel="loss<?php echo esc_attr($group['id']) ?>"><?php esc_html_e('L', 'pixieclash') ?></th>
<th rel="point<?php echo esc_attr($group['id']) ?>"><?php esc_html_e('P', 'pixieclash') ?></th>
</tr>
</thead>
<tbody>
<?php if(!empty($competitors)): foreach($competitors as $competitor): ?>
<tr>
<td>
<figure>
<img src="<?php echo esc_url($competitor['logo']) ?>" alt="<?php echo esc_attr($competitor['name']) ?>">
</figure>
<?php echo esc_attr($competitor['name']) ?>
</td>
<td rel="match<?php echo esc_attr($group['id']) ?>"><?php echo esc_attr($competitor['played']) ?></td>
<td rel="win<?php echo esc_attr($group['id']) ?>"><?php echo esc_attr($competitor['wins']) ?></td>
<td rel="till<?php echo esc_attr($group['id']) ?>"><?php echo esc_attr($competitor['till']) ?></td>
<td rel="loss<?php echo esc_attr($group['id']) ?>"><?php echo esc_attr($competitor['losses']) ?></td>
<td rel="point<?php echo esc_attr($group['id']) ?>"><?php echo esc_attr($competitor['points']) ?></td>
</tr>
<?php endforeach; else: ?>
<tr>
<td colspan="6"><?php esc_html_e('No competitors', 'pixieclash') ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
</article>
<?php $i ++; endforeach; endif; ?>
</div>
</section>
I tried to create the shortcode using add_shorcode('table', 'name of this function'); but this didn't work for me.
How can i do this?
returna string containing all of the content you want to replace the Shortcode placeholder.