{"id":35,"date":"2016-12-19T05:17:34","date_gmt":"2016-12-19T05:17:34","guid":{"rendered":"http:\/\/docs.generatepress.com\/?post_type=kp_articles&p=35"},"modified":"2018-11-29T19:47:50","modified_gmt":"2018-11-29T19:47:50","slug":"adding-php","status":"publish","type":"keep_articles","link":"https:\/\/docs.generatepress.com\/article\/adding-php\/","title":{"rendered":"Adding PHP"},"content":{"rendered":"\n

In some cases you may need to add a function to your website, either to hook something into the theme, or use a filter to change something in the theme.<\/p>\n\n\n\n

When working with PHP, you want to make sure you have access to your server via FTP or File Manager (through your hosting control panel). This is due to how unforgiving PHP is, if there’s an error in the code, your site can turn into a blank white page. To fix this, simply go into your server and delete the code you added.<\/p>\n\n\n\n

Code Snippets<\/h3>\n\n\n\n

The Code Snippets<\/a> plugin is a very cool way to add PHP snippets to your website. You can activate and deactivate certain snippets, and even adds notes about what they do. I believe it even has better error handling to avoid the PHP error scenario I mentioned above.<\/p>\n\n\n\n

To install it, simply go to Plugins > Add New<\/strong> and search for Code Snippets<\/strong>.<\/p>\n\n\n\n

Create a Plugin<\/h3>\n\n\n\n

If you don’t want to use the Code Snippets plugin mentioned above, you can create your own plugin.<\/p>\n\n\n\n

Usually, creating a plugin is kind of difficult, but we can actually use a plugin to make creating a plugin easier (still with me?).<\/p>\n\n\n\n

First, install Pluginception<\/a> by going to Plugins > Add New<\/strong> and searching for Pluginception<\/strong>.<\/p>\n\n\n\n

Now that it’s activated, go to Plugins > Create New Plugin<\/strong>.<\/p>\n\n\n\n

Name it something super specific to you so it doesn’t conflict with any other plugins, and create it.<\/p>\n\n\n\n

Now you can add your functions to the plugin file.<\/p>\n\n\n\n

Use a Child Theme<\/h3>\n\n\n\n

If you’re already using a child theme, you can use the functions.php file to add your PHP.<\/p>\n","protected":false},"template":"","yoast_head":"\nAdding PHP - Documentation<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/docs.generatepress.com\/article\/adding-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding PHP - Documentation\" \/>\n<meta property=\"og:description\" content=\"In some cases you may need to add a function to your website, either to hook something into the theme, or use a filter to change something in the theme. When working with PHP, you want to make sure you have access to your server via FTP or File Manager (through your hosting control panel). […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/docs.generatepress.com\/article\/adding-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Documentation\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GeneratePress\" \/>\n<meta property=\"article:modified_time\" content=\"2018-11-29T19:47:50+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@GeneratePress\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/docs.generatepress.com\/article\/adding-php\/\",\"url\":\"https:\/\/docs.generatepress.com\/article\/adding-php\/\",\"name\":\"Adding PHP - Documentation\",\"isPartOf\":{\"@id\":\"https:\/\/docs.generatepress.com\/#website\"},\"datePublished\":\"2016-12-19T05:17:34+00:00\",\"dateModified\":\"2018-11-29T19:47:50+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/docs.generatepress.com\/article\/adding-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/docs.generatepress.com\/article\/adding-php\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/docs.generatepress.com\/article\/adding-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/docs.generatepress.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Articles\",\"item\":\"https:\/\/docs.generatepress.com\/article\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Adding PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/docs.generatepress.com\/#website\",\"url\":\"https:\/\/docs.generatepress.com\/\",\"name\":\"Documentation\",\"description\":\"Get to Know GeneratePress\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/docs.generatepress.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Adding PHP - Documentation","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/docs.generatepress.com\/article\/adding-php\/","og_locale":"en_US","og_type":"article","og_title":"Adding PHP - Documentation","og_description":"In some cases you may need to add a function to your website, either to hook something into the theme, or use a filter to change something in the theme. When working with PHP, you want to make sure you have access to your server via FTP or File Manager (through your hosting control panel). […]","og_url":"https:\/\/docs.generatepress.com\/article\/adding-php\/","og_site_name":"Documentation","article_publisher":"https:\/\/www.facebook.com\/GeneratePress","article_modified_time":"2018-11-29T19:47:50+00:00","twitter_card":"summary_large_image","twitter_site":"@GeneratePress","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/docs.generatepress.com\/article\/adding-php\/","url":"https:\/\/docs.generatepress.com\/article\/adding-php\/","name":"Adding PHP - Documentation","isPartOf":{"@id":"https:\/\/docs.generatepress.com\/#website"},"datePublished":"2016-12-19T05:17:34+00:00","dateModified":"2018-11-29T19:47:50+00:00","breadcrumb":{"@id":"https:\/\/docs.generatepress.com\/article\/adding-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/docs.generatepress.com\/article\/adding-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/docs.generatepress.com\/article\/adding-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/docs.generatepress.com\/"},{"@type":"ListItem","position":2,"name":"Articles","item":"https:\/\/docs.generatepress.com\/article\/"},{"@type":"ListItem","position":3,"name":"Adding PHP"}]},{"@type":"WebSite","@id":"https:\/\/docs.generatepress.com\/#website","url":"https:\/\/docs.generatepress.com\/","name":"Documentation","description":"Get to Know GeneratePress","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/docs.generatepress.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/docs.generatepress.com\/wp-json\/wp\/v2\/keep-api\/35"}],"collection":[{"href":"https:\/\/docs.generatepress.com\/wp-json\/wp\/v2\/keep-api"}],"about":[{"href":"https:\/\/docs.generatepress.com\/wp-json\/wp\/v2\/types\/keep_articles"}],"wp:attachment":[{"href":"https:\/\/docs.generatepress.com\/wp-json\/wp\/v2\/media?parent=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}