Snippet library
PHP snippets for WordPress.
467 free & Pro snippets and modules. Copy-paste-ready, or import in one click with SnipCraft.
Auto-Login After Registration
Automatically authenticates a new user and redirects them to the site after they complete registration, removing the need to log in manually.
Add Logout Link to Navigation Menu
Appends a logout link (or a login link for guests) to the primary navigation menu, automatically using the correct URL and label based on auth state.
Disable Gravatar and Use Local Fallback Avatar
Prevents WordPress from requesting Gravatar images from external servers, returning a local placeholder for all users to improve privacy and load speed.
Set Custom Default Avatar
Registers a local image as a new default avatar option and forces it as the site default, replacing the generic mystery-person silhouette.
Add Custom Links Below Login Form
Appends a Privacy Policy and Terms of Service link beneath the WordPress login form using the login_footer action.
Disable Login Page Language Switcher
Removes the language/locale dropdown displayed beneath the WordPress login form, keeping the page minimal for single-language sites.
Extend Login Session Duration
Increases the WordPress authentication cookie lifetime to 30 days for a normal session and one year when "Remember Me" is checked.
Check Remember Me by Default on Login
Pre-checks the "Remember Me" checkbox on the WordPress login form using a small script injected into the login footer.
Disable New User Notification Emails
Suppresses both the admin notification and the default welcome email sent to the registrant whenever a new account is created.
Set Default Role for New Registrations
Overrides the default role assigned to newly registered users, setting it to "subscriber" regardless of the value saved in Settings → General.
Redirect Logged-In Users Away From Login Page
Sends already-authenticated visitors to the dashboard (admins) or homepage (others) when they attempt to load the login screen.
Redirect Users After Logout
Redirects users to the site homepage instead of the login screen after they click Log Out.
Notify Post Author of Comments
Ensures the original post author always receives a comment notification email, even when the admin and author share an email address.
Hold Comments With Many Links
Automatically queues comments for moderation when they contain more than a configurable number of hyperlinks.
Set Min/Max Comment Length
Rejects comment submissions that are shorter than a minimum or longer than a maximum character count.
Nofollow Comment Author Links
Ensures all comment author anchor tags carry rel="nofollow ugc" to prevent link-spam SEO benefit.
Remove URL Field from Comment Form
Removes the website URL field from the default WordPress comment form to reduce spam.
Disable Comments per Post Type
Removes comment support and meta boxes for a configurable list of post types, and gates the comments_open filter to match.
Disable Comments on Attachments
Prevents comments and pings from being opened on media attachment posts.
Close Comments on Old Posts
Programmatically closes comments and pings on posts older than a configurable number of days.
Insert Ad/CTA After First Paragraph
Injects a customisable call-to-action block immediately after the first paragraph of single post content.
Exclude Pages/Posts from Search
Removes specific post IDs and/or post types from the front-end search results query.
Exclude Categories from RSS Feed
Removes posts from specified categories from appearing in the site's RSS feed.
Delay Posts in RSS Feed
Withholds recently published posts from the RSS feed for a configurable number of hours to discourage content scraping.