# ultimate-post/2.5.6/addons/templates/Shortcode.php

Post Grid Gutenberg Blocks – PostX, version 2.5.6. 37 lines.

- Page: https://pluginprobe.com/plugins/ultimate-post/2.5.6/code/addons/templates/Shortcode.php
- Raw: https://pluginprobe.com/plugins/ultimate-post/2.5.6/raw/addons/templates/Shortcode.php
- Modified: 2022-05-20T17:54:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ultimate-post/2.5.6/code/addons/templates/Shortcode.php#L10-L20`.

```php
<?php
namespace ULTP;

defined('ABSPATH') || exit;

class Shortcode {
    public function __construct(){
        add_shortcode('gutenberg_post_blocks', array($this, 'shortcode_callback'));
        add_shortcode('postx_template', array($this, 'shortcode_callback'));
    }

    // Shortcode Callback
    function shortcode_callback( $atts = array(), $content = null ) {
        extract(shortcode_atts(array(
         'id' => ''
        ), $atts));

        $id = is_numeric( $id ) ? (float) $id : false;
        $content = '';
        if ($id) {
            $init = new \ULTP\ULTP_Initialization();
            $init->register_scripts_common();
            $css = ultimate_post()->set_css_style($id, true);
            $content_post = get_post($id);
            if ($content_post) {
                if ($content_post->post_status == 'publish' && $content_post->post_password == '') {
                    $content = $content_post->post_content;
                    $content = apply_filters('the_content', $content);
                    $content = str_replace(']]>', ']]&gt;', $content);
                    return $css.'<div class="ultp-shortcode" data-postid="'.$id.'">' . $content . '</div>';
                }
            }
        }
        return '';
    }
    
}
```
