---
title: "Adding custom PHP code snippets to your website"
date: 2026-04-23
author: "GravityKit"
link: "https://www.gravitykit.com/docs/gravityview/customizing-your-views/where-to-put-code-samples/"
---

**See also:**

- [Adding custom CSS to your Views](https://www.gravitykit.com/docs/gravityview/customizing-your-views/adding-custom-css-to-your-website/)
- [Adding custom JavaScript or jQuery code snippets to your Views](https://www.gravitykit.com/docs/gravityview/customizing-your-views/adding-custom-javascript-or-jquery-code-snippets-to-your-views/)
- [Using custom code in the View settings](https://www.gravitykit.com/docs/gravityview/view-settings/view-settings-custom-code/)
- [Using the Custom Content field](https://www.gravitykit.com/docs/gravityview/getting-started-gravityview/using-the-custom-content-field/)

On this Knowledge Base website, you'll see many code samples that allow you to modify GravityView functionality.

There are two ways of adding code to your website:

- Via a plugin
- Via the functions.php file of your currently active theme

### Adding code to your website with the help of a WordPress plugin

If you're not comfortable adding code to your theme's functions.php, then don't do it. If something goes wrong, you can break your website. It's safer to do it with the help of a plugin.

We recommend installing the following plugin on your WordPress website: [Code Snippets](https://wordpress.org/plugins/code-snippets/).

![Adding Code Snippets plugin in WordPress: Go to Add New, search "code snippets," click Install Now](https://www.gravitykit.com/wp-content/uploads/2025/10/file-gzs6ASJwaQ.png)
*After the plugin has been installed, you can add a new code snippet:*![Add a new PHP snippet with a description and save changes](https://www.gravitykit.com/wp-content/uploads/2025/10/file-gMM0TOYKk0.png)

### Adding code to your website by using the theme editor

You can edit your theme's functions.php file by:

- Hovering over the Appearance menu
- Clicking the "Theme Editor" link in the flyout menu that appears
- Clicking on the link named Theme Functions (functions.php)
- Modifying the code in the editor
- Click the "Update file" button

![Edit functions.php in the Theme Editor, add code at the file's end, and save changes](https://www.gravitykit.com/wp-content/uploads/2025/10/file-JQPwJb15LY.png)
*We do encourage you to learn how to add code yourself, but learning code always (yes, always!) eventually leads to breaking a site. Just know that going in, and you'll be fine :-)*

### Important tips when adding code:

Make sure not to include opening `
- The code should go after the `` at the end of the file (if it exists. It shouldn't, most of the time).
- Do not nest ````

```

```
php
// This code block shows what duplicate opening PHP tags looks like.

$existing_code = 'example';

php // 
$new_code = 'new code you pasted';
```

Instead, don't include the second ````

```

```
php
// This code block shows what correct opening PHP tags looks like.

$existing_code = 'example';

$new_code = 'new code you pasted';
```