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

Register Project Type Custom Taxonomy

Registers a hierarchical "Project Type" taxonomy attached to Portfolio and post types with REST API support.

#content#cpt#custom
PHPPro

Register Portfolio Custom Post Type

Registers a "Portfolio" custom post type with archive support, REST API visibility, and a portfolio dashicon.

#content#cpt#custom
PHPPro

Auto-Add target="_blank" and rel to External Links

Automatically adds target="_blank" and rel="noopener noreferrer" to all external links found in post content.

#content#frontend#links
PHPPro

Related Posts by Category Appended to Content

Appends a list of related posts from the same categories at the end of single post content.

#content#frontend#related-posts
PHPPro

Estimated Reading Time Shortcode

Adds a [reading_time] shortcode that calculates and displays estimated reading time based on word count.

#content#reading-time#seo
PHP

Back-to-Top Anchor Appended to Post Content

Appends a "Back to top" anchor link at the end of single post content via the_content filter.

#accessibility#content#frontend
PHP

Enable Shortcodes in Widgets and Excerpts

Allows shortcodes to be processed inside Classic Widget text blocks and post excerpt fields.

#content#everywhere#excerpts
PHP

Site Name and URL Shortcode

Adds a [site_name] shortcode that outputs the site name as plain text or a linked anchor with link="yes".

#branding#content#shortcode
PHP

Current Year Shortcode

Adds a [current_year] shortcode that outputs the current four-digit year, useful for copyright notices.

#content#copyright#date
PHP

Custom "Read More" Excerpt Link

Replaces the default […] excerpt suffix with a styled "Read more →" link to the full post.

#content#excerpts#frontend
PHP

Custom Excerpt Length

Sets the default WordPress excerpt word count to 25 words via the excerpt_length filter.

#content#excerpts#frontend
PHP

Mailchimp for WP: Redirect After Successful Sign-Up

Redirects the visitor to a custom thank-you page after a successful Mailchimp for WP form submission instead of showing the inline success message.

#forms#mailchimp#newsletter
PHPPro

Mailchimp for WP: Auto-Populate a Source Field on Sign-Up

Automatically appends the page URL as a SOURCE merge field to every Mailchimp for WP form submission so you can track which page each subscriber used.

#forms#mailchimp#merge-fields
PHPPro

BuddyPress: Redirect Profile Tab to Activity Feed

Redirects visitors away from the default BuddyPress profile public tab to the member's activity feed, making activity the first thing displayed on profile pages.

#activity#buddypress#profile
PHP

bbPress: Change Topics Per Page

Overrides the number of topics displayed per page in bbPress forum listings by filtering the bbp_get_topics_per_page value.

#bbpress#forum#pagination
PHPPro

bbPress: Auto-Close Stale Topics via Scheduled Task

Registers a daily WP-Cron event that automatically closes any bbPress topics older than a configurable number of days to reduce forum maintenance.

#bbpress#cron#forum
PHPPro

LearnDash: Auto-Enroll New Users in a Free Course

Automatically enrolls every newly registered user into a specified LearnDash course ID, ideal for an onboarding or free introductory course.

#courses#enrollment#learndash
PHPPro

LearnDash: Redirect User After Course Completion

Fires on the learndash_course_completed action and redirects the student to a configurable thank-you or next-steps page when they finish a course.

#completion#courses#learndash
PHPPro

MemberPress: Customize the Post-Login Redirect for Members

Redirects members to a custom dashboard page after logging in via MemberPress, while sending admins to wp-admin and non-members to the default redirect.

#dashboard#login#memberpress
PHPPro

MemberPress: Redirect Non-Members Away from Protected Content

Checks MemberPress access rules on singular posts and redirects any user without access to the login page, preserving the intended destination URL.

#access-control#memberpress#membership
PHPPro

The Events Calendar: Override the Default Events Slug

Changes the public URL slug used for the events archive (e.g. /events/ → /whats-on/) via the tribe_events_rewrite_slugs filter without touching plugin settings.

#events#permalink#rewrite
PHPPro

The Events Calendar: Sort Event Archive by Start Date

Forces the main Events Calendar archive to order events by start date ascending so upcoming events always appear first, overriding any default sort.

#archive#events#query
PHP

The Events Calendar: Change Events Per Page

Overrides the Events Calendar events-per-page setting via filter so you can control the listing count in code without visiting the plugin settings.

#events#frontend#pagination
PHP

Rank Math: Remove the Admin Bar Node

Removes the Rank Math SEO node from the WordPress admin bar so it no longer appears on the front end or in wp-admin.

#admin-bar#cleanup#rank-math