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']);
        ?>
</section>

and the function related to this section in my functions.php:

function pixieclash_standings($id) {
global $tables;

if(!$id) {
    return false;
}

// Get Standing Groups
$sponsors = pixieclash_select_all($tables['standings'], ['group_id', $id], ['points', 'DESC']);
return $sponsors;}

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?

Read more here: How to create shortcode with html and php content?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: