25% off ProSNIPC25OFF

Snippet library

PHP snippets for WordPress.

467 free & Pro snippets and modules. Copy-paste-ready, or import in one click with SnipCraft.

PHPPro

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.

#login#registration#users
PHP

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.

#login#menu#navigation
PHP

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.

#avatars#performance#privacy
PHP

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.

#avatars#customization#profile
PHP

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.

#customization#links#login
PHP

Disable Login Page Language Switcher

Removes the language/locale dropdown displayed beneath the WordPress login form, keeping the page minimal for single-language sites.

#customization#language#login
PHP

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.

#cookies#login#session
PHP

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.

#login#session#users
PHP

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.

#email#notifications#registration
PHP

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.

#access#registration#roles
PHP

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.

#login#redirect#users
PHP

Redirect Users After Logout

Redirects users to the site homepage instead of the login screen after they click Log Out.

#login#logout#redirect
PHP

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.

#authors#comments#email
PHP

Hold Comments With Many Links

Automatically queues comments for moderation when they contain more than a configurable number of hyperlinks.

#comments#moderation#security
PHP

Set Min/Max Comment Length

Rejects comment submissions that are shorter than a minimum or longer than a maximum character count.

#comments#content#moderation
PHP

Nofollow Comment Author Links

Ensures all comment author anchor tags carry rel="nofollow ugc" to prevent link-spam SEO benefit.

#comments#links#security
PHP

Remove URL Field from Comment Form

Removes the website URL field from the default WordPress comment form to reduce spam.

#comments#forms#frontend
PHPPro

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.

#admin#comments#moderation
PHP

Disable Comments on Attachments

Prevents comments and pings from being opened on media attachment posts.

#attachments#comments#media
PHP

Close Comments on Old Posts

Programmatically closes comments and pings on posts older than a configurable number of days.

#comments#content#moderation
PHPPro

Insert Ad/CTA After First Paragraph

Injects a customisable call-to-action block immediately after the first paragraph of single post content.

#ads#content#cta
PHP

Exclude Pages/Posts from Search

Removes specific post IDs and/or post types from the front-end search results query.

#content#filtering#frontend
PHP

Exclude Categories from RSS Feed

Removes posts from specified categories from appearing in the site's RSS feed.

#categories#content#feed
PHP

Delay Posts in RSS Feed

Withholds recently published posts from the RSS feed for a configurable number of hours to discourage content scraping.

#content#feed#rss