Skip to content

Instantly share code, notes, and snippets.

@knolaust
knolaust / wp-update-urls-in-db.php
Last active January 30, 2024 15:09
Update WordPress URLs in MySQL Database
<?php
/**
* Update URLs in the WordPress database when migrating from old URL to new URL.
*
* This function updates various tables and fields in the WordPress database to reflect the new URL
* when migrating a WordPress site.
*
* Usage:
* - Backup your WordPress database before running this function.
* - Call the function with the old URL and new URL as arguments to execute the updates.
@knolaust
knolaust / wp-get-cpt-posts-by-custom-tax.php
Last active January 30, 2024 15:08
Get posts from Custom Post Type grouped by Custom Taxonomy
<?php
/**
* Get posts from Custom Post Type grouped by Custom Taxonomy
*
* Gist Keywords: wordpress, custom post types, cpt, taxonomy
* Author: Knol Aust
* Version: 1.0.0
* Description: This code retrieves posts from a custom post type and groups them by a custom taxonomy.
*/
@knolaust
knolaust / wp-modify-admin-footer-text.php
Last active January 30, 2024 15:08
Give a WordPress admin page a custom line of text in Dashboard footer
@knolaust
knolaust / wp-remove-clutter-from-head.php
Last active January 30, 2024 15:07
Remove unecessary WordPress clutter from header.
<?php
/**
* Remove Unnecessary WordPress Header Clutter
*
* This code snippet removes unnecessary elements from the WordPress header to improve page load and security.
* Place this code in your theme's functions.php file.
*
* Gist Keywords: wordpress, security, performance
*
* @category Performance
@knolaust
knolaust / wp_ga_footer.php
Last active January 30, 2024 15:07
Add Google Analytics 4 to WordPress footer
@knolaust
knolaust / wordpress_if-parent-or-child.php
Last active January 30, 2024 15:07
This function (add to functions.php file) creates new logical function to determine if page is parent or child
<?php
/**
* Check if Page is a Child of Another Page
* Gist Keywords: wordpress, parent, child, hierarchy
*
* @category WordPress
* @author Knol Aust
* @version 1.0.0
* @description Function to determine if the current page is a child of a specific parent page.
*/
@knolaust
knolaust / wp-api-get-menu.php
Last active January 30, 2024 15:06
Function for WordPress that creates custom endpoint to return menu using WP-Rest-API
<?php
/**
* Custom REST API Endpoint: Get Menu
* Gist Keywords: wordpress, rest, api
*
* @category WordPress
* @author Knol Aust
* @version 1.0.0
* @description Retrieves a WordPress menu using a custom REST API endpoint.
*/
@knolaust
knolaust / wp-custom-endpoint.php
Last active January 30, 2024 15:06
Custom endpoint for WP API returning multiple queries
<?php
/**
* Custom REST API Endpoint: Get Home Content
* Gist Keywords: wordpress, api, rest, content
*
* @category WordPress
* @author Knol Aust
* @version 1.0.0
* @description Retrieves featured content and the three most recent posts via a custom REST API endpoint. This example shows you can use one endpoint to pull in various queries from the API for a page like frontpage.
*/
@knolaust
knolaust / create-admin-via-functions.php
Last active January 30, 2024 15:05
Create WP Admin User via functions.php
<?php
/**
* Automatically Create WordPress Admin Account
* Gist Keywords: wordpress, admin, user
*
* @category WordPress
* @author Knol Aust
* @version 1.0.0
* @description Automatically creates a WordPress admin account with specified credentials if it doesn't exist. Function should only be run once to inject the user and removed from functions.php when completed.
*/
@knolaust
knolaust / divi-responsive-images.php
Last active January 30, 2024 15:05
Adds Responsive Images to DIVI theme.
<?php
/**
* Adds better responsive images to DIVI theme
* Gist Keywords: wordpress, divi, enqueue
*
* @category WordPress
* @author Knol Aust
* @version 1.0.0
* @description Adds better responsive images to DIVI
*/