Title: Adding code to function.php
Last modified: August 22, 2016

---

# Adding code to function.php

 *  [ocean_jasper](https://wordpress.org/support/users/ocean_jasper/)
 * (@ocean_jasper)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/adding-code-to-functionphp/)
 * 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](https://wordpress.org/support/topic/how-to-add-codes-in-functionphp?replies=6)“)
   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.

## Tags

 * [function.php](https://wordpress.org/support/topic-tag/function-php/)

 * 0 replies
 * 1 participant
 * Last reply from: [ocean_jasper](https://wordpress.org/support/users/ocean_jasper/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/adding-code-to-functionphp/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
