{"id":5437950,"date":"2014-10-31T02:29:27","date_gmt":"2014-10-31T02:29:27","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/adding-code-to-functionphp\/"},"modified":"2016-08-22T03:59:17","modified_gmt":"2016-08-22T03:59:17","slug":"adding-code-to-functionphp","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/adding-code-to-functionphp\/","title":{"rendered":"Adding code to function.php"},"content":{"rendered":"<p>I would like to add the following code that was provided by Document Gallery plugin, to allow PDFs to open in a new window:<\/p>\n<pre><code>&lt;?php\nfunction dg_target_blank(){ ?&gt;\n&lt;script type=&quot;text\/javascript&quot;&gt;\n  jQuery(document).ready( function(){\n      jQuery(&#039;.document-icon &gt; a&#039;).attr(&#039;target&#039;, &#039;_blank&#039;);\n  } );\n&lt;\/script&gt;\n&lt;?php }\nadd_action( &#039;wp_print_footer_scripts&#039;, &#039;dg_target_blank&#039; );<\/code><\/pre>\n<p>Another post on this site (&#8220;<a href=\"https:\/\/wordpress.org\/support\/topic\/how-to-add-codes-in-functionphp?replies=6\">How to add codes in function.php<\/a>&#8220;) 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&#8217;t load, and I had to go to my server to restore my function.php file to its original. <\/p>\n<p>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&#8217;t execute. <\/p>\n<p>So then I tried deleting &#8220;&lt;?php&#8221; from the beginning of my text insertion.  Again I got the white screen, and had to go to my server.<\/p>\n<p>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!!<\/p>\n","protected":false},"template":"","class_list":["post-5437950","topic","type-topic","status-closed","hentry","topic-tag-function-php"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5437950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5437950\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5437950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}