This functions.php file is a dynamic and continuously evolving script for customizing WordPress functionality.
It serves as the backbone for adding bespoke features, optimizing processes, and adapting the WordPress environment
to specific project needs.
- Enhance WordPress flexibility beyond its default behavior.
- Keep code clean and documented for easier maintenance and collaboration.
- Provide a centralized location for custom hooks, actions, and utilities.
-
regenerateThumbnails- Regenerates thumbnails for all images in the WordPress media library.
- Checks if image files exist before processing.
-
custom_admin_logo_image_url+custom_admin_logo- Resolves admin logo URL with child-theme fallback support.
- Replaces default WordPress admin logo via injected admin CSS.
-
mcw_get_attachment_id_from_image_url+mcw_featured_image_in_feeds- Resolves attachment IDs from image URLs, including fallback for resized image file names (e.g.
-300x200). - Adds the first content image (or featured image fallback) into RSS feed content.
- Includes a safe guard when global
$postis unavailable.
- Resolves attachment IDs from image URLs, including fallback for resized image file names (e.g.
-
Post duplication tools (
custom_duplicate_post_link,custom_duplicate_post_as_draft)- Adds a "Duplicate" action for posts/pages/custom post types.
- Uses nonce verification, sanitized query input handling, and post-level capability checks.
- Duplicates core fields, taxonomies, and metadata.
- Handles insert failures safely.
-
custom_duplicate_admin_notice- Shows success notice after duplication.
- Sanitizes query parameters before usage.
-
Admin notifications page (
move_admin_notifications_to_menu,admin_notifications_page,disable_admin_notifications_from_main_screen)- Moves admin notices into a dedicated dashboard page.
- Sanitizes current page query checks before removing notice hooks.
-
add_last_modified_date_to_feed- Prepends a "Last updated" date in RSS excerpt/content output.
-
register_current_year_shortcode+render_current_year_shortcode- Registers
[current_year]shortcode. - Returns the current year using
wp_date('Y').
- Registers
-
mcw_allow_safe_svg_uploads- Enables SVG uploads only for admins.
-
mcw_add_image_performance_attributes
- Adds
loading="lazy"anddecoding="async"attributes to frontend content images.
mcw_close_attachment_comments
- Automatically disables comments/pingbacks on media attachment pages.
mcw_remove_asset_query_strings
- Removes query strings from CSS/JS asset URLs on frontend for better cache hit rates.
mcw_auto_set_featured_image_from_content
- Auto-assigns featured image from the first content image when no featured image exists.
mcw_register_reading_time_rest_field+mcw_get_reading_time_for_rest
- Adds
reading_time_minutesin REST API responses for posts/pages. - Calculates reading time from content word count.
mcw_register_reading_time_shortcode+mcw_render_reading_time_shortcode
- Registers
[reading_time]shortcode for displaying estimated reading time.
mcw_add_basic_security_headers
- Adds baseline security headers (
X-Content-Type-Options,X-Frame-Options,Referrer-Policy) to frontend responses.
- The admin notifications
Notescomment block infunctions.phpis intentionally kept at the very end of the file. - Every function in
functions.phpis wrapped with multi-lineStart/Endcomments (example style:/* Start: ... */and/* End: ... */), so each block is easy to copy/paste independently.