Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
danielbachhuber / blog-archive.php
Last active January 21, 2022 02:26
Creating a blog post archive at /blog/ without awkwardly publishing a page
<?php
add_filter( 'register_post_type_args', function( $args, $post_type ) {
global $wp_rewrite;
if ( 'post' === $post_type && ! is_null( $wp_rewrite ) ) {
$archive_slug = 'blog';
// Setting 'has_archive' ensures get_post_type_archive_template() returns an archive.php template.
$args['has_archive'] = $archive_slug;
// We have to register rewrite rules, because WordPress won't do it for us unless $args['rewrite'] is true.
$archive_slug = $wp_rewrite->root . $archive_slug;
@brasofilo
brasofilo / plugin.php
Last active April 6, 2020 01:13
Original code for Multisite Categories. At WordPress Answers http://wordpress.stackexchange.com/a/50936/12615
<?php
/**
* Plugin Name: Multisite Site Category
* Plugin URI: https://gist.github.com/brasofilo/6715423
* Description: Add a custom meta option when registering new sites in WordPress Multisite. Two columns will be added to the Sites listing screen: ID and Category. Based on http://wordpress.stackexchange.com/a/50936/12615
* Network: true
* Author: Rodolfo Buaiz
* Author URI: http://brasofilo.com/
* Version: 1.1
@justintadlock
justintadlock / register-post-type.php
Last active July 17, 2024 10:14
Help file when registering post types.
<?php
# Register custom post types on the 'init' hook.
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 1.0.0
* @access public
<?php
if ( !function_exists( 'wpcom_vip_load_category_base' ) ):
/**
* Enables a custom or no category base, if the site wants to use one that's not the WP.com default (/category/)
*
* Usage:
* wpcom_vip_load_category_base( '' );
* wpcom_vip_load_category_base( 'section' );
*
@sterlingwes
sterlingwes / tourney.html
Created December 3, 2012 23:42
Tournament Bracket Generator (Javascript + CSS, no tables)
<!DOCTYPE html>
<html>
<head>
<title>Tournament Bracket Generator</title>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://underscorejs.org/underscore-min.js"></script>
<script>
$(document).on('ready', function() {
var knownBrackets = [2,4,8,16,32], // brackets with "perfect" proportions (full fields, no byes)