Ultimate Post Shortcodes

Below, you’ll find a detailed guide on how to add the Ultimate Post Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Ultimate Post Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Ultimate Post Plugin and the shortcodes it provides:

Plugin Icon
Post Grid Gutenberg Blocks and WordPress Blog Plugin – PostX

"PostX is a versatile Post Grid Gutenberg Blocks and WordPress Blog Plugin. It enables the effortless creation, customization, and management of beautiful blog layouts and post grids on your WordPress website."

★★★★☆ (171) Active Installs: 30000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [gutenberg_post_blocks]
  • [postx_wpbakery_widget]

Ultimate Post [gutenberg_post_blocks] Shortcode

The Ultimate Post shortcode ‘gutenberg_post_blocks’ enables users to display specific posts within their WordPress site. It fetches the post content based on the ‘id’ attribute, which should be the post’s ID. The shortcode ensures the post is published and not password-protected before displaying. It also removes unnecessary HTML tags for cleaner content. The post content is wrapped in a ‘div’ with a class ‘ultp-shortcode’ for easy styling.

Shortcode: [gutenberg_post_blocks]

Parameters

Here is a list of all possible gutenberg_post_blocks shortcode parameters and attributes:

  • id – Numerical value representing the unique post ID

Examples and Usage

Basic example – The shortcode is used to display a post block by referencing the ID.

[gutenberg_post_blocks id=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [gutenberg_post_blocks] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('gutenberg_post_blocks', array($this, 'shortcode_callback'));

Shortcode PHP function:

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

        $id = is_numeric( $id ) ? (float) $id : false;

        if ($id) {
            $content = '';
            if (!isset($GLOBALS['wp_scripts']->registered['ultp-script'])) {
                ultimate_post()->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 = do_blocks($content);
                    $content = do_shortcode($content);
                    $content = str_replace(']]>', ']]>', $content);
                    $content = preg_replace('%<p>&nbsp;\s*</p>%', '', $content);
                    $content = preg_replace('/^(?:<br\s*\/?>\s*)+/', '', $content);
                    return $css.'<div class="ultp-shortcode" data-postid="'.$id.'">' . $content . '</div>';
                }
            }
        }
        return '';
    }

Code file location:

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

Ultimate Post [postx_wpbakery_widget] Shortcode

The PostX wpbakery_widget shortcode is a dynamic tool that outputs the content of a chosen saved template. This shortcode fetches the attributes of the saved template and displays its content. If the template is empty or nonexistent, it prompts the user to select a saved template or create a new one. This shortcode also supports Visual Composer’s frontend editor mode.

Shortcode: [postx_wpbakery_widget]

Examples and Usage

Basic example – The following shortcode displays a post template that has been previously saved in the ‘PostX > Saved Templates’ section of the WordPress dashboard. The ‘saved_template’ attribute refers to the ID of the saved template.

[postx_wpbakery_widget saved_template=1 /]

Advanced examples

Displaying a saved template while also enabling the ‘vc_editable’ mode. This mode allows the template to be editable within the Visual Composer page builder. In this example, ‘vc_editable’ is set to ‘true’ and ‘saved_template’ is set to ‘2’.

[postx_wpbakery_widget saved_template=2 vc_editable=true /]

Displaying a saved template without any template styling. This can be useful when you want to apply custom styles to the template. In this example, ‘saved_template’ is set to ‘3’ and ‘style’ is set to ‘false’.

[postx_wpbakery_widget saved_template=3 style=false /]

Please note that the actual output of these shortcodes will depend on the content and design of your saved templates, as well as the settings and styles of your WordPress theme and plugins.

PHP Function Code

In case you have difficulties debugging what causing issues with [postx_wpbakery_widget] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'postx_wpbakery_widget', __CLASS__ . '::output' );

Shortcode PHP function:

function output( $atts, $content = null ) {
            $output = '';
            $atts = vc_map_get_attributes( 'postx_wpbakery_widget', $atts );

            $body_class = get_body_class();
            $templates = $atts['saved_template'];
            
            if ( $templates && $templates != 'empty' ) {
                ultimate_post()->register_scripts_common();
                if (isset($_GET['vc_editable'])) {
                    $output .= ultimate_post()->set_css_style($templates, true);
                } else {
                    ultimate_post()->set_css_style($templates);
                }

                $args = array( 'p' => $templates, 'post_type' => 'ultp_templates' );
                $the_query = new \WP_Query($args);

                if ( $the_query->have_posts() ) {
                    while ($the_query->have_posts()) {
                        $the_query->the_post();
                        ob_start();
                        the_content();
                        $output .= ob_get_clean();
                    }
                    wp_reset_postdata();
                }
            } else {
                if ( isset($_GET['vc_editable']) ) {
                    $output .= '<p style="text-align:center;">'.sprintf( esc_html__( 'Pick a Template from your saved ones. Or create a template from: %s.' , 'ultimate-post' ) . ' ', '<strong><i>' . esc_html( 'Dashboard > PostX > Saved Templates', 'ultimate-post' ) . '</i></strong>' ).'</p>';
                }
            }

            return $output;
        }

Code file location:

ultimate-post/ultimate-post/addons/wpbakery/wpbakery.php

Conclusion

Now that you’ve learned how to embed the Ultimate Post Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *