Skip to content

Instantly share code, notes, and snippets.

<?php
add_action( 'after_setup_theme', 'wphc_theme_setup' );
function wphc_theme_setup() {
add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
) );
<?php
add_action( 'pre_get_posts', 'wphc_modify_orderby_books' );
function wphc_modify_orderby_books( $wp_query ) {
if ( false === $wp_query->is_main_query() || false === $wp_query->is_post_type_archive( 'books' ) {
return;
}
$wp_query->set( 'orderby', 'title' );
<?php
add_action( 'wp', 'wphc_redirect_url' );
function wphc_redirect_url() {
if ( ! is_singular() ) {
return;
}
$redirect = get_post_meta( get_the_ID(), 'redirect_url', true );
@CodeProKid
CodeProKid / term-swap.php
Last active April 26, 2017 19:21
wp-cli command to swap terms
<?php
class RK_Term_Swap extends WP_CLI {
/**
* Swaps one term for another on posts.
*
* ## OPTIONS
* <origin_term>
* : The term ID or slug of the term you want to query against, and remove from existing posts
*
@CodeProKid
CodeProKid / wp-exclude-child-categories.php
Last active July 29, 2023 13:16
Exclude child categories from a category archive page in WordPress
<?php
/**
* Excludes child terms from the main query on the category archive.
*
* @param object $query the WP_Query instance
* @return void
* @access public
*/
function rk_fix_tax_queries_on_archives( $query ) {
@CodeProKid
CodeProKid / sticky.php
Last active July 13, 2020 17:52
Add sticky functionality to CPT's
<?php
add_action( 'admin_init', 'cpt_sticky_add_meta_box' );
add_filter( 'the_posts', 'cpt_sticky_at_top' );
add_filter( 'post_limits', 'fix_post_count', 10, 2 );
function cpt_sticky_meta() { ?>
<input id="super-sticky" name="sticky" type="checkbox" value="sticky" <?php checked( is_sticky() ); ?> /> <label for="super-sticky" class="selectit"><?php _e( 'Stick this to the top' ) ?></label><?php
}