• I would like to add the following code that was provided by Document Gallery plugin, to allow PDFs to open in a new window:

    <?php
    function dg_target_blank(){ ?>
    <script type="text/javascript">
      jQuery(document).ready( function(){
          jQuery('.document-icon > a').attr('target', '_blank');
      } );
    </script>
    <?php }
    add_action( 'wp_print_footer_scripts', 'dg_target_blank' );

    Another post on this site (“How to add codes in function.php“) advises I should just add it to the end of the function.php file. When I did this and updated, the window went white, WordPress wouldn’t load, and I had to go to my server to restore my function.php file to its original.

    Based on a video tutorial I found, I tried created a my_function.php document and adding it here. The function.php successfully called up my_function.php, but the Document Gallery code simply didn’t execute.

    So then I tried deleting “<?php” from the beginning of my text insertion. Again I got the white screen, and had to go to my server.

    As may be obvious, I am an absolute novice and know nothing about coding. Would appreciate someone who can tell me how to do this!!

The topic ‘Adding code to function.php’ is closed to new replies.