Skip to content

Instantly share code, notes, and snippets.

@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
*
@knolaust
knolaust / wp-replace-howdy.php
Last active January 30, 2024 14:47
Change "Howdy Admin" in Admin Bar
<?php
/**
* Customizes the WordPress admin bar greeting text.
*
* This function replaces the default "Howdy," text in the WordPress admin bar with a custom greeting text.
*
* Usage:
* - Edit the value of the `$new_howdy` variable to set the desired greeting text.
*
* @param WP_Admin_Bar $wp_admin_bar The WordPress admin bar object.
@knolaust
knolaust / add-slug-body-class.php
Last active January 30, 2024 14:48
WordPress: Add the Page Slug to Body Class
<?php
/**
* Adds a custom class to the body tag in WordPress based on post type and name.
*
* This function modifies the classes applied to the body tag of a WordPress page.
* It adds a class that combines the post type and the post's slug (name).
* This can be useful for applying specific CSS styles to different pages or posts.
*
* Gist Keywords: wordpress, functions, body, css, styles
*
@knolaust
knolaust / remove-wpversion.php
Last active January 30, 2024 14:48
Remove WordPress Version Number
<?php
/**
* Removes the WordPress version number from the HTML generator tag.
*
* This function attaches to the 'the_generator' filter hook and replaces the
* default WordPress generator string with an empty string. This is often used
* for security purposes to obscure the WordPress version number.
*
* @link https://developer.wordpress.org/reference/hooks/the_generator/ WordPress Hook: the_generator
*
@knolaust
knolaust / disable-block-editor.php
Last active January 30, 2024 14:49
Disable Gutenberg Editor (use Classic Editor) in WordPress
<?php
/**
* Disables the Gutenberg editor for editing posts.
*
* This snippet attaches to both 'gutenberg_can_edit_post' and
* 'use_block_editor_for_post' hooks to disable the Gutenberg editor,
* reverting to the classic WordPress editor. The priority is set to 5
* to ensure this runs early enough to override any default settings.
*
* Gist Keywords: wordpress, editor, gutenberg, classic