Skip to content

Instantly share code, notes, and snippets.

View adamslowe's full-sized avatar

Adam Lowe adamslowe

View GitHub Profile
@kellenmace
kellenmace / remove-custom-post-type-slug-from-permalinks.php
Last active June 6, 2021 03:19
Remove custom post type slug from permalinks in WordPress
<?php
/**
* Remove the slug from published post permalinks. Only affect our custom post type, though.
*/
function gp_remove_cpt_slug( $post_link, $post ) {
if ( 'race' === $post->post_type && 'publish' === $post->post_status ) {
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
}
@vwasteels
vwasteels / getMenuHierarchically.md
Last active June 28, 2022 13:12
Retrieve menu items hierarchically in Wordpress
/**
 * Get Menu Items From Location
 *
 * @param $location : location slug given as key in register_nav_menus
 */

function getMenuItemsFromLocation($location) {
	$theme_locations = get_nav_menu_locations();
@mattclements
mattclements / function.php
Last active May 11, 2026 01:04
Wordpress Disable Comments (add to function.php)
<?php
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
@generatepress
generatepress / remove-customize-sections
Last active October 6, 2022 03:09
Remove sections from GeneratePress Customize area
add_action( 'customize_register', function( $wp_customize ) {
// Remove default sections
$wp_customize->remove_section('generate_colors_section');
$wp_customize->remove_section('generate_typography_section');
$wp_customize->remove_panel('generate_layout_panel');
// Remove Menu Plus section.
$wp_customize->remove_panel('generate_menu_plus');
// Remove Generate Backgrounds section
@luetkemj
luetkemj / wp-query-ref.php
Last active April 8, 2026 18:20
WP: Query $args
// This gist is now maintained on github at https://github.com/luetkemj/wp-query-ref
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.github.io
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/