WordPress
functions.php Generator
Generate common functions.php snippets for theme customization and WordPress configuration.
Configuration
Generated PHP
// Select a snippet type on the left to generate functions.php code
functions.php Generator — WordPress Theme Development Made Easier
The functions.php file is the backbone of any WordPress theme. It acts like a plugin for your theme, letting you register post types, enqueue assets, add theme support features, and configure navigation menus. This generator produces correctly structured, hook-wrapped PHP code that follows WordPress coding standards.
When to Use Each Snippet
- Custom Post Type (CPT) — Use when you need a new content model beyond posts and pages. CPTs are registered on the
inithook and should always be added to a plugin (not a theme) if the content must persist when the theme changes. - Taxonomy — Add classification systems like categories and tags to any post type. Set
hierarchical = truefor a category-like taxonomy (parent/child), orfalsefor a free-tagging taxonomy like post tags. - Enqueue Scripts & Styles — Always enqueue assets via
wp_enqueue_scriptsrather than hardcoding them in templates. This allows plugins to dequeue or replace them and ensures correct dependency loading order. - Theme Support — Use
add_theme_support()to opt into WordPress features.title-taglets WordPress manage the<title>element.post-thumbnailsenables featured images.html5switches core output to HTML5 markup. - Nav Menu — Register locations where navigation menus can be assigned from the Appearance > Menus admin screen.
Best Practices
- Namespace all your functions with a unique prefix (e.g.,
mytheme_) to avoid conflicts with other themes or plugins. - Never modify core WordPress files — use hooks and filters in
functions.phpinstead. - For CPTs and taxonomies that should persist across theme changes, register them in a plugin rather than a theme.
- Use
get_stylesheet_directory_uri()when enqueueing assets for child themes, notget_template_directory_uri().