Skip to content

Instantly share code, notes, and snippets.

@knolaust
knolaust / coming_soon_plugin.php
Created November 19, 2025 20:53
Displays a Coming Soon page to visitors while allowing logged-in users or anyone with a secret preview link to view the site.
<?php
/**
* Plugin Name: Coming Soon Mode
* Description: Displays a Coming Soon page to visitors while allowing logged-in users or anyone with a secret preview link to view the site.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@knolaust
knolaust / force_wp_mail_from.php
Created November 17, 2025 14:53
Force WordPress core system emails to use a specific from address & name.
<?php
/**
* Force WordPress core system emails to use a specific from address & name.
*/
add_filter( 'wp_mail_from', function( $email ) {
return '[email protected]'; // your domain address
});
add_filter( 'wp_mail_from_name', function( $name ) {
return 'From Name'; // whatever label you want
@knolaust
knolaust / shortcode-for-reddit.php
Last active April 30, 2025 16:07
Shortcode for Reddit User
function render_acf_gallery_shortcode() {
if ( ! have_rows( 'gallery' ) ) {
return '<p>No gallery items found.</p>';
}
$thumbnails = '';
$images = [];
$infos = [];
while ( have_rows( 'gallery' ) ) {
@knolaust
knolaust / disable-speculative-loading.php
Created April 16, 2025 14:03
Disable WP Speculative Loading
<?php
/**
* Disable Speculative Loading in WordPress
*
* WordPress 6.5+ introduces speculative loading (like prerendering and prefetching)
* to improve perceived performance by preloading likely navigation targets.
* This filter disables the feature entirely, which can be helpful if:
* - You're troubleshooting performance issues
* - You use dynamic or cache-sensitive content
* - You want full control over browser loading behavior
@knolaust
knolaust / ka-hide-wordpress-for-guests.php
Created July 10, 2024 20:14
This function hides all WordPress content from users who are not logged in. Visitors will see a custom message instead of any pages or posts, except for the login page.
<?php
/**
* Hide entire site unless logged in.
*
* Gist Keywords: wordpress, privacy
* Author: Knol Aust
* Version: 1.0.0
* Description: This function hides all WordPress content from users who are not logged in. Visitors will see a custom message instead of any pages or posts, except for the login page.
*/
@knolaust
knolaust / wp-replace-logo.php
Last active January 30, 2024 14:45
Replace WordPress Logo on Login Page
<?php
/**
* Customize WordPress Login Logo.
*
* This code replaces the default WordPress logo on the login page with a custom logo.
* Update the URL to your custom logo and adjust the width and height accordingly.
*
* Gist Keywords: wordpress, admin, login
*
* @category WordPress
@knolaust
knolaust / wp-open-in-new-tab.php
Last active January 30, 2024 14:45
Open External Links in WordPress Content Blocks or Editors in a New Tab
<?php
/**
* Modify External Links to Open in New Tab.
*
* This code modifies external links within the post content to open in a new tab
* and adds the "noopener noreferrer" attributes for security.
*
* Gist Keywords: wordpress, customization
*
* @category WordPress
@knolaust
knolaust / wp-duplicate-post-link.php
Last active January 30, 2024 14:46
Duplicate Post/Page Link in WordPress Admin
<?php
/**
* Add Duplicate Button to Post/Page List of Actions in WordPress Admin.
*
* This code adds a "Duplicate" button to the list of actions for posts and pages
* in the WordPress admin, allowing users to quickly duplicate a post or page.
*
* Gist Keywords: wordpress, duplicate, posts, pages, functionality
*
* @category WordPress
@knolaust
knolaust / wp-disable-jquery-migrate.php
Last active January 30, 2024 14:46
Disable jQuery Migrate in WordPress
<?php
/**
* Remove jQuery Migrate dependency from jQuery in the frontend.
*
* This function removes the jQuery Migrate script dependency from the jQuery script
* when loading scripts in the frontend to improve performance.
*
* Gist Keywords: wordpress, jquery, javascript, performance
*
* @category WordPress
@knolaust
knolaust / wp-disable-attachment-pages.php
Last active January 30, 2024 14:47
Disable Attachment Pages in WordPress
<?php
/**
* Redirect attachments to their parent posts or homepage.
*
* This function checks if the current page is an attachment and if it has a parent post.
* If the attachment has a parent post that is not trashed, it redirects to the parent post.
* If the attachment has no parent or the parent post is trashed, it redirects to the homepage.
*
* Gist Keywords: wordpress, disable attachment, pages
*