functions.php Snippet Builder
Build a functions.php file from common WordPress snippets
Build a functions.php file from common WordPress snippets
<?php
// Add to your child theme's functions.php
// Toggle snippets to build your file.
A WordPress theme's functions.phpruns on every page load, before any template file. It's where you register theme supports, enqueue scripts and styles, and hook into WordPress's action and filter system to change behavior without editing core or plugin files. Think of it as a theme-scoped plugin.
Editing the parent theme's functions.php directly means every theme update wipes your changes. Instead, create a child theme — a directory containing a style.css that references the parent in its header and a functions.phpthat enqueues the parent stylesheet. Your snippets live in the child's functions.php and survive updates. For site-wide snippets unrelated to presentation, a small custom plugin or the Code Snippets plugin is usually a cleaner home than the theme.
add_action()attaches a callback to a named "event" — WordPress calls it at specific points like init, wp_enqueue_scripts, or admin_menu. The callback doesn't return anything meaningful.add_filter() attaches a callback that transforms a value. Whatever the callback returns becomes the new value. Example: modifying the excerpt length or the list of allowed upload MIME types.functions.php can white-screen your site.mysite_disable_comments) so they don't collide with the theme or plugins.WP_DEBUG on during development and tailwp-content/debug.log to see warnings early.