Malicious code in functions.php, footer files or templates should be reviewed by comparison against a trustworthy baseline, not by deleting every unfamiliar line. Theme customization, child themes and deployment patches can all look “non-standard”; provenance and behavioral impact separate legitimate divergence from injection.
Choose the right baseline
Use the exact theme/version, child-theme repository or deployment artifact that should own the file. A baseline from another version can create false positives.
Diff before editing
Capture file hash and a focused diff showing added, removed or changed blocks. Preserve timestamps separately because copying a clean file will overwrite useful incident timing.
Classify each divergence
Separate expected customization from unexplained loaders, remote includes, conditional redirects, hidden JavaScript or credential/data access. Review hooks and execution context around the change.
Check related template surfaces
If one theme file is modified, compare sibling templates, mu-plugins and writable override locations. Attackers often choose several load paths rather than one obvious file.
Restore from source, then reapply known changes
Prefer a clean package/repository version and reintroduce documented customizations instead of manually deleting fragments from a contaminated file.
Verify render paths and integrity
Test representative frontend/admin pages, recalculate hashes and monitor for new modifications. A clean diff immediately after repair is not enough if the write path remains open.
Use recent-file analysis to build the timeline and reinfection-route verification to confirm the files stay clean.