Pdf Poster Shortcode

Below, you’ll find a detailed guide on how to add the Pdf Poster 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 Pdf Poster Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Pdf Poster Plugin and the shortcodes it provides:

Plugin Icon
PDF Poster – PDF Embedder Plugin for WordPress

"PDF Poster is a powerful PDF Embedder Plugin for WordPress. It allows users to seamlessly integrate and display PDF files on their website, enhancing user experience and content accessibility."

★★★★☆ (135) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: 7.1
Included Shortcodes:
  • [pdf]

Pdf Poster [pdf] Shortcode

The PDF Poster plugin shortcode is a function that dynamically generates a PDF based on the given post ID. It first checks if the post type is ‘pdfposter’. If not, it returns false. If the plugin was updated after the post was published and the post content is not empty, or if the post was created using Gutenberg, it uses the AdvanceSystem to generate the HTML. Otherwise, it uses the AnalogSystem.

Shortcode: [pdf]

Parameters

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

  • id – The unique identifier for the specific post

Examples and Usage

Basic example – Use the shortcode to display a PDF poster by referencing its ID.

[pdf id=1 /]

Advanced examples

Display a PDF poster by referencing its ID. If the PDF poster is not found or if the plugin was updated after the publish date of the PDF poster and the content of the post is not empty or if the post was created using Gutenberg editor, the advanced system will be used to generate the HTML. Otherwise, the analog system will be used.

[pdf id=1 pluginUpdated=1630223686 publishDate=1630223685 isGutenberg=true /]

Display a PDF poster by referencing its ID. If the PDF poster is not found or if the plugin was updated before the publish date of the PDF poster and the content of the post is not empty or if the post was not created using Gutenberg editor, the analog system will be used to generate the HTML. Otherwise, the advanced system will be used.

[pdf id=1 pluginUpdated=1630223686 publishDate=1630223687 isGutenberg=false /]

PHP Function Code

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

Shortcode line:

add_shortcode('pdf', [$this, 'pdf'], 10, 2);

Shortcode PHP function:

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

    $post_type = get_post_type($id);
    $pluginUpdated = 1630223686;
    $publishDate = get_the_date('U', $id);
    $isGutenberg = get_post_meta($id, 'isGutenberg', true);
    $post = get_post($id);

    
    ob_start(); 
    
    if($post_type !== 'pdfposter'){
      return false;
    }

    if($pluginUpdated < $publishDate && $post->post_content != '' || $isGutenberg){
      echo( AdvanceSystem::html($id));
    }else {
      echo Analogsystem::html($id);
    }
    
    return ob_get_clean(); 
  }

Code file location:

pdf-poster/pdf-poster/inc/Services/Shortcode.php

Conclusion

Now that you’ve learned how to embed the Pdf Poster 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 *