Skip to content
Public Ticket #25704

Custom shortcode

Conversation thread

PenciDesign Supporter replied

Staff Reply

Hi,

Have you added this code to your site?

add_shortcode('my_shortcode','my_custom_shortcode');

Regards,
PenciDesign.


Nurmukhan replied

Customer Reply

Если я добавлю шорткод без WP Bakery и через сделать шорткод на странице, но результат будет таким же

PenciDesign Supporter replied

Staff Reply

Hi,

Please send me the screenshot of the settings page you've added this code.

Regards,
PenciDesign.


PenciDesign Supporter replied

Staff Reply

Hi,

For this case, please send me your WordPress admin account in a PRIVATE reply.
I'll log in and try to help you check it.

Regards,
PenciDesign.



Nurmukhan started the conversation

Conversation Start

I created my own shortcode to display popular news for the day, week, month and year, data from the Post view Counter plugin. When outputting the shortcode, nothing is output, and all the collected on the main page disappear and in its place becomes an empty output of news. In my shortcode, I added my own css and js, adding them to function.php and activating them in the template settings as a shortcode. Here is an example of my php code: 

<div id="tab1" class="tab active"><?php
$today_start = date('Y-m-d 00:00:00');
$today_end = date('Y-m-d 23:59:59');

$popular_posts = pvc_get_most_viewed_posts(array(
    'posts_per_page' => 4,
    'orderby' => 'views',
    'order' => 'DESC',
  'start' => $today_start,
  'end' => $today_end,
    'date_query' => array(
        'after' => $today_start,
        'before' => $today_end,
        'inclusive' => true,
    ),
));

foreach ($popular_posts as $post) {
    setup_postdata($post);
?>
    <div class="gallery-item">
        <?php if (has_post_thumbnail()) { ?>
            <div style="background-image: url(<?php esc_url(the_post_thumbnail_url('full')); ?>);">
                <?php the_post_thumbnail('gallery-item', array('class' => 'custom-thumbnail-class')); ?>
            </div>
        <?php } ?>
        <span class="caption">
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php echo get_the_date('F j, Y'); ?>
        </span>
    </div>
<?php
}
wp_reset_postdata();
?>
    </div> 

Want to join this conversation or access attachments? Sign in first.