Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
chrisguitarguy / custom-shortlink.php
Created August 29, 2011 22:14
Adds a custom shortlink structure to WordPress
@wpscholar
wpscholar / wp-redirect.php
Last active April 14, 2020 15:37
WordPress function for redirecting users on login based on user role
<?php
/**
* WordPress function for redirecting users on login based on user role
*/
function my_login_redirect( $url, $request, $user ){
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if( $user->has_cap( 'administrator' ) ) {
$url = admin_url();
} else {
@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
*/
@glueckpress
glueckpress / block-wp-login.php
Created April 12, 2012 07:28
Block ANY access to wp-login.php and redirect to a given URL (here: home_url() ).
<?php
add_action( 'init', 'custom_init_function' );
function custom_init_function() {
global $pagenow;
if( ! is_user_logged_in() && 'wp-login.php' == $pagenow ) {
wp_redirect( home_url() ); // redirect URL
exit();
@billerickson
billerickson / gist:3698476
Last active February 23, 2024 16:49 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@codler
codler / startpage-text.php
Created October 8, 2012 16:30
Startpage Text Widget Wordpress
<?php
/*
Plugin Name: Startpage Text Widget
Plugin URI: http://yap.nu/
Description: Custom Description Text on startpage
Author: Han Lin Yap
Version: 1 (2012-10-08)
Author URI: http://yap.nu/
*/
@WebEndevSnippets
WebEndevSnippets / functions.php
Created October 23, 2012 16:43
WordPress: Add Category ID in Admin
add_filter( 'manage_edit-category_columns', 'we_categoriesColumnsHeader' );
add_filter( 'manage_category_custom_column', 'we_categoriesColumnsRow', 10, 3 );
/**
* Add Category ID column in admin
*
*/
function we_categoriesColumnsHeader($columns) {
$columns['catID'] = __('ID');
return $columns;
}
@Vheissu
Vheissu / gist:4063547
Created November 13, 2012 02:15
Wordpress has a nasty and annoyingly known bug that prevents paginated custom post type pages from abiding by a set posts_per_page value, this sets it straight. Replace the post type value of "project" with your own custom post type name, you can add OR c
/**
* Wordpress has a known bug with the posts_per_page value and overriding it using
* query_posts. The result is that although the number of allowed posts_per_page
* is abided by on the first page, subsequent pages give a 404 error and act as if
* there are no more custom post type posts to show and thus gives a 404 error.
*
* This fix is a nicer alternative to setting the blog pages show at most value in the
* WP Admin reading options screen to a low value like 1.
*
*/
@WPsites
WPsites / gist:4128809
Created November 22, 2012 01:03
Hide admin menu items on a WordPress site.
<?php
/*
The code below hides the admin menu items for all users that don't have the 'manage_sites' capability.
On multisite that would mean only Super Admins can look at those menu items
This script only removes the menu items so users can still look at the page if they know the path, but it de-clutters the admin
*/
global $current_user;
if ( !current_user_can('manage_sites') ) {
@lauhakari
lauhakari / wp-pagination-url.php
Last active December 28, 2021 01:07
Change the pagination url in Wordpress (3+) You can put in a plugin file or your functions.php.
<?php
add_action( 'init', 'my_custom_page_word' );
function my_custom_page_word() {
global $wp_rewrite; // Get the global wordpress rewrite-rules/settings
// Change the base pagination property which sets the wordpress pagination slug.
$wp_rewrite->pagination_base = "new-slug"; //where new-slug is the slug you want to use ;)
}