Skip to content

Instantly share code, notes, and snippets.

@dboutote
dboutote / feed_filter.php
Last active February 23, 2016 20:28
Limit a WordPress feed to one post type.
<?php
function my_feed_filter($query) {
if ( $query->is_feed && 'cpt_shop' === $query->get('post_type') ) {
$query->set('order', 'asc');
$query->set('meta_key', '_alt_title');
$query->set('orderby', 'meta_value');
};
return $query;
};
add_filter('pre_get_posts','my_feed_filter');
@dboutote
dboutote / edit-tags.js
Last active February 20, 2016 18:22
Removes link around locked tags; removes <span> from title attr. term_name filter.
( function ($) {
'use strict';
var locked_tags = $('table.tags .dashicons-lock').parents('a.row-title');
locked_tags.contents().unwrap().parent().wrapInner('<span class="row-title"></span>');
locked_tags.attr('title', function(){
return 'Edit "' + $.trim( $(this).html().replace(/<[^>]+>/ig,"") ) + '"';
});
@dboutote
dboutote / raw_html.php
Last active February 13, 2016 02:13
Encoding HTML in WordPress Posts: https://wordpress.org/plugins/wp-post-encode/
<?php
function dbdb_quick_encode($content_text) {
$charset = get_bloginfo('charset');
$replaced_text = preg_replace('#(<!--encode-->)(.*?)(<!--/encode-->)#isme', "'$1'.str_replace(array('<!--nextpage-->', '<!--more-->'), array('&lt;!--nextpage--&gt;', '&lt;!--more--&gt;'), '$2').'$3'", $content_text);
foreach($replaced_text as $k => $v ) {
$encoded_text[$k] = str_replace(array('"'),array('"'), $v);
}
return $encoded_text;
};
add_filter('wp_insert_post_data','dbdb_quick_encode', 1, 1);
@dboutote
dboutote / category_tax_fix.php
Created January 11, 2016 04:51
Instruct WordPress to search on all post types when doing a category taxonomy query.
<?php
function post_type_category_fix($request) {
if ( isset($request['category_name']) && !isset($request['post_type']) )
$request['post_type'] = 'any';
return $request;
};
add_filter('request', 'post_type_category_fix');
@dboutote
dboutote / post_tags_tax_fix.php
Last active January 11, 2016 04:51
Instruct WordPress to search on all post types when doing a post_tag taxonomy query.
<?php
function post_type_tags_fix($request) {
if ( isset($request['tag']) && !isset($request['post_type']) )
$request['post_type'] = 'any';
return $request;
};
add_filter('request', 'post_type_tags_fix');
@dboutote
dboutote / email_filters.php
Created January 11, 2016 04:47
Filtering the WordPress email address
<?php
function site_mail_from(){
$admin_email = get_option('admin_email');
return $admin_email;
};
add_filter('wp_mail_from', 'site_mail_from');
function site_mail_from_name(){
@dboutote
dboutote / post_class_filter.php
Last active January 11, 2016 04:45
Customizing the WordPress post_class Filter
<?php
function my_post_classes( $classes ) {
global $multipage, $page, $post, $wp_taxonomies;
if($wp_taxonomies) {
foreach($wp_taxonomies as $taxonomy) {
$tax_array[] = $taxonomy->name;
}
@dboutote
dboutote / site_setup.php
Created January 11, 2016 04:35
Basic WordPress site set up functionality
<?php
function site_setup() {
// This network uses post thumbnails
add_theme_support( 'post-thumbnails' );
// enable excerpts on page post_types
add_post_type_support('page', 'excerpt');
// Adds RSS feed links to <head> for posts and comments.
add_theme_support( 'automatic-feed-links' );
@dboutote
dboutote / external_links.js
Created January 9, 2016 20:34
jQuery script to add target=“_blank” for outgoing links
@dboutote
dboutote / template-include.php
Last active December 30, 2015 23:39
WordPress: Load a template file on singe-post-type page (if applicable)
<?php
/**
* Load a template file on single-post-type page (if applicable)
*
* Works for all post-types
*/
function dbdb_include_post_template($template) {
if( !is_archive() ) {
$id = get_queried_object_id();
$template_name = get_post_meta($id, '_wp_page_template', true);