Sunday, April 19, 2026
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 init hook 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 = true for a category-like taxonomy (parent/child), or false for a free-tagging taxonomy like post tags.
  • Enqueue Scripts & Styles — Always enqueue assets via wp_enqueue_scripts rather 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-tag lets WordPress manage the <title> element. post-thumbnails enables featured images. html5 switches 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.php instead.
  • 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, not get_template_directory_uri().