Print My Blog Shortcode

Below, you’ll find a detailed guide on how to add the Print My Blog Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Print My Blog Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Print My Blog Plugin and the shortcodes it provides:

Plugin Icon
Print My Blog – Print, PDF, & eBook Converter WordPress Plugin

"Print My Blog is a versatile WordPress plugin that enables users to convert their blogs into print, PDF, or eBook formats. Ideal for archiving, sharing, and offline reading."

★★★★☆ (92) Active Installs: 5000+ Tested with: 6.2.3 PHP Version: 5.4
Included Shortcodes:
  • [vrview]

Print My Blog [vrview] Shortcode

The Print-My-Blog shortcode is designed to embed 360-degree images or videos into your WordPress posts. It accepts parameters for image, video, preview image, stereo, width, and height. The shortcode generates an iframe URL, which is then converted into a clickable link. If a preview image is provided, it is displayed. Otherwise, a default text “360 Image Available” is shown.

Shortcode: [vrview]

Parameters

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

  • img – URL of the image to display in 360 view
  • video – URL of the video to play in 360 view
  • pimg – URL of the preview image before video load
  • stereo – Determines if the image or video is in stereo format, default is ‘false’
  • width – Sets the maximum width of the displayed image or video
  • height – Sets the maximum height of the displayed image or video

Examples and Usage

Basic example – A simple usage of the shortcode to display an image with a default size of 640×360.

[vrview img="http://example.com/image.jpg" /]

Advanced examples

Displaying a stereo image with a custom size of 800×600.

[vrview img="http://example.com/image.jpg" stereo="true" width="800" height="600" /]

Displaying a video with a preview image.

[vrview video="http://example.com/video.mp4" pimg="http://example.com/preview.jpg" /]

Displaying a video with a preview image and custom size.

[vrview video="http://example.com/video.mp4" pimg="http://example.com/preview.jpg" width="800" height="600" /]

Displaying a video in stereo mode with a preview image and custom size.

[vrview video="http://example.com/video.mp4" pimg="http://example.com/preview.jpg" stereo="true" width="800" height="600" /]

PHP Function Code

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

Shortcode line:

add_shortcode('vrview', [$this, 'shortcode']);

Shortcode PHP function:

function shortcode($atts)
    {
        // code mostly copy-and-pasted from wp-vr-view's vr_creation()
        $a = shortcode_atts(
            array(
                'img' => '',
                'video' => '',
                'pimg' => '',
                'stereo' => 'false',
                'width' => '640',
                'height' => '360',
            ),
            $atts
        );

        $img_url = 'image=' . $a['img'];
        $stereo = '&is_stereo=' . $a['stereo']; // generate s_stereo parameter -  defaul is FALSE

        /* if has video then add it to URL */
        $video_url = '';
        if ($a['video']) {
            $video_url = 'video=' . $a['video'];
            if ($a['img']) {
                $img_url = '&image=' . $a['img'];
            } else {
                $img_url = '';
            }
        }
        /* if has preview then add it to URL */
        $pimg_url = '';
        if ($a['pimg']) {
            $pimg_url = '&preview=' . $a['pimg'];
        }

        // ==================================================================
        // MODIFIED FROM ORIGINAL because original just used plugin_dir_url(__FILE__) from WP VR View's main file
        $iframe_url = plugin_dir_url(
            dirname(dirname(PMB_MAIN_FILE))
            . '/wp-vr-view/wp-vrview.php'
        )
            . 'asset/index.html?'
            . $video_url
            . $img_url
            . $stereo
            . $pimg_url;

        // turn it into a link instead of an iframe here
        $html = '<div class="pmb-wp-vr-view-wrapper"><a href="' . $iframe_url . '">';

        if (isset($a['pimg']) && $a['pimg']) {
            $html .= '<img class="wp-vr-view pmb-video-preview" style="max-width:'
                . $a['width']
                . ';max-height:'
                . $a['height']
                . '" src="'
                . esc_url($a['pimg']) . '">';
        } else {
            $html .= '<p>' . __('360 Image Available', 'print-my-blog') . '</p>';
        }

        $html .= '</a></p></div>';
        return $html;
    }

Code file location:

print-my-blog/print-my-blog/src/PrintMyBlog/compatibility/plugins/WpVrView.php

Conclusion

Now that you’ve learned how to embed the Print My Blog Plugin shortcode, 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 *