Skip to content

Instantly share code, notes, and snippets.

View adamslowe's full-sized avatar

Adam Lowe adamslowe

View GitHub Profile
@luetkemj
luetkemj / wp-query-ref.php
Last active May 25, 2024 10:56
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
*/
@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
@mattclements
mattclements / function.php
Last active July 2, 2024 15:32
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;
}
@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();
@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 );
}
@m-thomson
m-thomson / import-image-fix.md
Last active June 23, 2023 14:12
WP All Import duplicate image problem

When an image is imported, the name used in the media library is derived from the URL "basename". This can cause problems, especially when using the option "Search through the Media Library for existing images before importing new images". For example, even though they are different images, these URLs all have the same "basename" (in bold). They will generate the same file my-image.jpg in the WordPress library:

http:// example.com/ my-image.jpg
http:// example.com/ my-image?id=1
http:// example.com/subfolder/ my-image.jpg

The solution is to put this PHP code in your function editor:

function fix_img_url($url){
@heiswayi
heiswayi / repo-reset.md
Created February 5, 2017 01:32
GitHub - Delete commits history with git commands

First Method

Deleting the .git folder may cause problems in our git repository. If we want to delete all of our commits history, but keep the code in its current state, try this:

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A
@mcguffin
mcguffin / acf-quick-edit-rgba-color-picker.php
Last active June 29, 2021 16:57
ACF RGBA Color Picker + ACF Quick Edit Fields
<?php
/**
* Bringing ACF RGBA Color Picker and ACF QuickEdit Fields together.
* https://github.com/mcguffin/acf-quick-edit-fields
* https://wordpress.org/plugins/acf-rgba-color-picker/
*/
/**
* Add field support
*/
@yankiara
yankiara / oxygen-repeater-dynamic-query.php
Last active September 6, 2023 19:25
Use dynamic queries with Oxygen's repeater
/* I'll put here different examples of dynamic query for Oxygen repeater :
* - Use one of the following repeater_dynamic_query definitions
* in code block just BEFORE the repeater
* - Set the repeater custom query settings : post type, number of posts, order...
* - Add the remove_action in a code block AFTER the repeater
*/
/****************************************************************************************************
* Display related posts for any CPT with taxonomy:
@zackpyle
zackpyle / *Best Snippets*
Last active May 1, 2024 20:05
Best PHP/JS Snippets
This is a collection of my most used or most useful PHP and JS snippets
**Disclaimer, I didn't write most of these - I just curated them over the years**