{"slug":"wordpress-theme-development","title":"WordPress Theme Development","tags":["development","theme","functions-php","enqueue"],"agent_summary":"Complete pattern for custom WordPress theme setup including style.css header, functions.php essentials, script enqueueing, widget registration, and menu setup.","trigger_phrases":["wordpress theme development","custom wordpress theme","functions.php setup","wp_enqueue_scripts","wordpress theme from scratch"],"runnable":true,"markdown":"\nCustom WordPress themes require a specific file structure and setup sequence. Build on a starter theme (GeneratePress, Kadence, or Underscores) rather than from blank when possible.\n\n## Required Files\n\n```\nmy-theme/\n├── style.css          # Theme header + base styles\n├── functions.php      # Theme setup, enqueue, hooks\n├── index.php          # Fallback template\n├── header.php         # Site header\n├── footer.php         # Site footer\n├── page.php           # Default page template\n├── single.php         # Single post template\n├── archive.php        # Archive/taxonomy template\n├── 404.php            # 404 template\n└── template-parts/    # Reusable partials\n```\n\n## style.css Theme Header\n\n```css\n/*\nTheme Name: My Custom Theme\nTheme URI: https://example.com/theme\nAuthor: Your Name\nAuthor URI: https://example.com\nDescription: Custom theme for [client]\nVersion: 1.0.0\nRequires at least: 6.0\nTested up to: 6.5\nRequires PHP: 8.1\nLicense: GPL v2 or later\nText Domain: my-theme\n*/\n```\n\n## functions.php Essentials\n\n```php\n<?php\nfunction mytheme_setup() {\n    add_theme_support('title-tag');\n    add_theme_support('post-thumbnails');\n    add_theme_support('html5', ['search-form', 'comment-form', 'gallery', 'caption']);\n    add_theme_support('responsive-embeds');\n    add_theme_support('editor-styles');\n\n    register_nav_menus([\n        'primary' => __('Primary Menu', 'my-theme'),\n        'footer'  => __('Footer Menu', 'my-theme'),\n    ]);\n\n    add_image_size('hero', 1920, 800, true);\n    add_image_size('card', 400, 300, true);\n}\nadd_action('after_setup_theme', 'mytheme_setup');\n\nfunction mytheme_scripts() {\n    wp_enqueue_style('mytheme-style', get_stylesheet_uri(), [], '1.0.0');\n    wp_enqueue_style('mytheme-main', get_template_directory_uri() . '/assets/css/main.css', [], '1.0.0');\n\n    wp_enqueue_script('mytheme-main', get_template_directory_uri() . '/assets/js/main.js', ['jquery'], '1.0.0', true);\n\n    wp_localize_script('mytheme-main', 'mythemeAjax', [\n        'ajaxUrl' => admin_url('admin-ajax.php'),\n        'nonce'   => wp_create_nonce('mytheme_nonce'),\n    ]);\n}\nadd_action('wp_enqueue_scripts', 'mytheme_scripts');\n\nfunction mytheme_widgets() {\n    register_sidebar([\n        'name'          => __('Sidebar', 'my-theme'),\n        'id'            => 'sidebar-1',\n        'before_widget' => '<div class=\"widget %2$s\">',\n        'after_widget'  => '</div>',\n        'before_title'  => '<h3 class=\"widget-title\">',\n        'after_title'   => '</h3>',\n    ]);\n}\nadd_action('widgets_init', 'mytheme_widgets');\n```\n\n## Version Control\n\nTrack theme with Git. Initialize in the theme folder (`wp-content/themes/my-theme/`), not the WordPress root. Add `node_modules/`, `*.log`, and `*.DS_Store` to `.gitignore`.\n","html":"<p>Custom WordPress themes require a specific file structure and setup sequence. Build on a starter theme (GeneratePress, Kadence, or Underscores) rather than from blank when possible.</p>\n<h2>Required Files</h2>\n<pre><code>my-theme/\n├── style.css          # Theme header + base styles\n├── functions.php      # Theme setup, enqueue, hooks\n├── index.php          # Fallback template\n├── header.php         # Site header\n├── footer.php         # Site footer\n├── page.php           # Default page template\n├── single.php         # Single post template\n├── archive.php        # Archive/taxonomy template\n├── 404.php            # 404 template\n└── template-parts/    # Reusable partials\n</code></pre>\n<h2>style.css Theme Header</h2>\n<pre><code class=\"language-css\">/*\nTheme Name: My Custom Theme\nTheme URI: https://example.com/theme\nAuthor: Your Name\nAuthor URI: https://example.com\nDescription: Custom theme for [client]\nVersion: 1.0.0\nRequires at least: 6.0\nTested up to: 6.5\nRequires PHP: 8.1\nLicense: GPL v2 or later\nText Domain: my-theme\n*/\n</code></pre>\n<h2>functions.php Essentials</h2>\n<pre><code class=\"language-php\">&#x3C;?php\nfunction mytheme_setup() {\n    add_theme_support('title-tag');\n    add_theme_support('post-thumbnails');\n    add_theme_support('html5', ['search-form', 'comment-form', 'gallery', 'caption']);\n    add_theme_support('responsive-embeds');\n    add_theme_support('editor-styles');\n\n    register_nav_menus([\n        'primary' => __('Primary Menu', 'my-theme'),\n        'footer'  => __('Footer Menu', 'my-theme'),\n    ]);\n\n    add_image_size('hero', 1920, 800, true);\n    add_image_size('card', 400, 300, true);\n}\nadd_action('after_setup_theme', 'mytheme_setup');\n\nfunction mytheme_scripts() {\n    wp_enqueue_style('mytheme-style', get_stylesheet_uri(), [], '1.0.0');\n    wp_enqueue_style('mytheme-main', get_template_directory_uri() . '/assets/css/main.css', [], '1.0.0');\n\n    wp_enqueue_script('mytheme-main', get_template_directory_uri() . '/assets/js/main.js', ['jquery'], '1.0.0', true);\n\n    wp_localize_script('mytheme-main', 'mythemeAjax', [\n        'ajaxUrl' => admin_url('admin-ajax.php'),\n        'nonce'   => wp_create_nonce('mytheme_nonce'),\n    ]);\n}\nadd_action('wp_enqueue_scripts', 'mytheme_scripts');\n\nfunction mytheme_widgets() {\n    register_sidebar([\n        'name'          => __('Sidebar', 'my-theme'),\n        'id'            => 'sidebar-1',\n        'before_widget' => '&#x3C;div class=\"widget %2$s\">',\n        'after_widget'  => '&#x3C;/div>',\n        'before_title'  => '&#x3C;h3 class=\"widget-title\">',\n        'after_title'   => '&#x3C;/h3>',\n    ]);\n}\nadd_action('widgets_init', 'mytheme_widgets');\n</code></pre>\n<h2>Version Control</h2>\n<p>Track theme with Git. Initialize in the theme folder (<code>wp-content/themes/my-theme/</code>), not the WordPress root. Add <code>node_modules/</code>, <code>*.log</code>, and <code>*.DS_Store</code> to <code>.gitignore</code>.</p>\n"}