Title: [Plugin: PHP Code Widget] Generated [pdf] short code not working ..
Last modified: August 19, 2016

---

# [Plugin: PHP Code Widget] Generated [pdf] short code not working ..

 *  Resolved [Tanveer](https://wordpress.org/support/users/tanver/)
 * (@tanver)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-php-code-widget-generated-pdf-short-code-not-working/)
 * Hi All,
    My website is [http://floodreliefpakistan.com/](http://floodreliefpakistan.com/),
   am using the `PHP Code Widget` – code given below – to generate the following
   HTML at run time using ul, il tags to format the output.
 * > [pdf href=”[http://floodreliefpakistan.com/pdfdocs/CosmicTechSol.pdf”%5DCosmicTechSol](http://floodreliefpakistan.com/pdfdocs/CosmicTechSol.pdf”%5DCosmicTechSol)[/
   > pdf]
   >  [pdf href=”[http://floodreliefpakistan.com/pdfdocs/Cosmic-Tech-Sol.pdf”%5DCosmic](http://floodreliefpakistan.com/pdfdocs/Cosmic-Tech-Sol.pdf”%5DCosmic)
   > Tech Sol [/pdf]
 * When I place this generated code in the `Text Widget` it executes perfectly but
   am unable to get the desired results from this `PHP code Widget`. The PHP Code
   which is being executed from within this Widget is
 *     ```
       <?php
       $chArr[] = '-';
       $chArr[] = '.pdf';
       if ($handle = opendir('pdfdocs')) {
         echo '<ul>';
         while (false !== ($file = readdir($handle))) {
           if ($file != "." && $file != "..") { ?>
               <li>[pdf href="http://floodreliefpakistan.com/pdfdocs/<?php echo $file; ?>"]<?php echo str_replace($chArr, ' ', $file); ?>[/pdf]</li>
       <?php
           }
         }
         echo '</ul>';
         closedir($handle);
       }
       ?>
       ```
   
 * and the output it generates can be observed by visiting the following the URL`
   http://floodreliefpakistan.com/test.php`.
 * Any help to resolve this issue is highly appreciated.
    TIA
 * [http://wordpress.org/extend/plugins/php-code-widget/](http://wordpress.org/extend/plugins/php-code-widget/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [Tanveer](https://wordpress.org/support/users/tanver/)
 * (@tanver)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-php-code-widget-generated-pdf-short-code-not-working/#post-1647818)
 * I just changed the code – took away the shortcode – and it had worked for me,
   am putting the code here as it might help someone else, the complete code for
   the PHP Code Widget is ..
 *     ```
       <?php
       $chArr[] = '-';
       $chArr[] = '.pdf'; 
   
       if ($handle = opendir('pdfdocs')) {
         while (false !== ($file = readdir($handle))) {
           if ($file != "." && $file != "..") {
               $pdfdocs[] = $file;
           }
         }
         closedir($handle);
       }
       ?>
   
       <?php
       echo '<ul>';
       foreach($pdfdocs as $pdfdoc) {
         //echo '<li> [pdf href="http://floodreliefpakistan.com/pdfdocs/'.$pdfdoc.'"]View '.str_replace($chArr, " ", $pdfdoc).'[/pdf]</li>';
       ?>
         <li> <a class="pdf" href="http://docs.google.com/viewer?url=http://floodreliefpakistan.com/pdfdocs/<?php echo $pdfdoc; ?>">View <?php echo str_replace($chArr," ", $pdfdoc); ?></a></li>
       <?php
       }
       echo '</ul>';
       unset($pdfdocs);    // it's gone
       ?>
       ```
   
 * hope it helps someone.
 * The one thing still left desirable is that I would like the google’s document
   window to open in a new window instead of appearing in the same window.
    TIA

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: PHP Code Widget] Generated [pdf] short code not working ..’ 
is closed to new replies.

 * ![](https://ps.w.org/php-code-widget/assets/icon.svg?rev=992095)
 * [PHP Code Widget](https://wordpress.org/plugins/php-code-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/php-code-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/php-code-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/php-code-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/php-code-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/php-code-widget/reviews/)

## Tags

 * [html not working](https://wordpress.org/support/topic-tag/html-not-working/)

 * 1 reply
 * 1 participant
 * Last reply from: [Tanveer](https://wordpress.org/support/users/tanver/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-php-code-widget-generated-pdf-short-code-not-working/#post-1647818)
 * Status: resolved