Guides
Adding PHP in Wordpress

Info

Guides
May 11, 2026

Guide

The methods below are usually the safest and cleanest options for adding PHP to your projects.

Option 1: Snippets plugin (recommended)

Use a snippets plugin to add your PHP code, then activate it from there. This is the safest option because snippets are easier to manage, disable, and troubleshoot if something goes wrong.

You can use any trusted snippets plugin. I personally use Code Snippets, but other reputable snippet plugins can work too.

Most snippet plugins automatically handle the opening PHP tag for you. If the plugin you are using does not add it by default, make sure your PHP snippet starts with:

<?php

// your snippet here

Option 2: Add PHP to your theme

You can also add PHP directly to your theme files, usually inside functions.php.

This works, but it is easier to break things if you are not careful. Theme updates can also overwrite your changes unless you are using a child theme.

For most users, the snippets plugin method is cleaner, safer, and easier to manage.