Skip to content

Instantly share code, notes, and snippets.

View josephhinson's full-sized avatar

Joseph Hinson josephhinson

View GitHub Profile
@josephhinson
josephhinson / WordPress Permalink Override
Created May 28, 2013 17:33
This snippet overrides the WordPress permalink with a custom field called "post_URL" if that custom field exists.
@josephhinson
josephhinson / Pull content from any page given the slug, WordPress shortcode
Last active December 17, 2015 20:59
So, you want to pull content from one page into another...maybe you have an "upcoming events" section that you want to be its own page, yet you also want to show on another page. This shortcode will help you do that. Put this code in your functions.php file.
<?php
// [page name="contact"]
function page_content($atts) {
extract(shortcode_atts(array(
'name' => ''
), $atts));
$return = '';
$args=array(
'name' => $name,
'post_type' => 'page',
@josephhinson
josephhinson / new_read_more.php
Created October 30, 2013 14:43
[WordPress] When you want to add "Read More" to all excerpts, regardless of length
<?php
// Excerpt Filter this will remove any text added to the excerpt
function new_excerpt_more($more) {
global $post;
return '';
}
// This will append the excerpt with additional text, "Read More"
function the_excerpt_always_show_read_more($content) {
global $post;
@josephhinson
josephhinson / taxonomy-archive.php
Created November 5, 2013 13:55
Taxonomy archive page for some reason, WordPress doesn't seem to like the taxonomy archive by default, so I usually end up creating this page, it's a bit of a hack, but it works. Name it taxonomy-your_taxonomy.php -- obviously edit as needed, but the code should work universally...
<?php get_header(); ?>
<div class="container blog content">
<div class="row">
<div class="span8 entry">
<div class="headline">
<?php
$value = get_query_var($wp_query->query_vars['taxonomy']);
$cat = get_term_by('slug',$value,$wp_query->query_vars['taxonomy']); ?>
<h1><?php echo $cat->name; ?></h1>
<?php $loop = new WP_Query(array(
@josephhinson
josephhinson / searchfilter.php
Last active December 28, 2015 10:29
Search Filter (to return results by post type). Create a custom search form where you can set a hidden input to search that specific post type...see below the PHP block.
<?php
function otg_optional_search_filter($query) {
$post_type = $_GET['type'];
if (!$post_type) {
$post_type = 'any';
}
if ($query->is_search) {
$query->set('post_type', $post_type);
};
return $query;
@josephhinson
josephhinson / triangleFold.less
Created November 18, 2013 17:46
CSS Folding triangle from corner of any element
.triangleFold(@size, @basebackground, @foldcolor) {
&:after {
content: '';
width: 0;
height: 0;
border-left: @size solid transparent;
border-right: 0px solid transparent;
border-bottom: @size solid @basebackground;
position: absolute;
bottom: 0px;
@josephhinson
josephhinson / filterArchive.php
Last active December 29, 2015 09:19
Insert this function into your functions file or plugin in order to filter your post type archive results.
<?php
function my_new_posts_filter($query) {
// in place of "press" put your custom post type -- you can add additional post types by duplicating the if block.
// you can also add more query variables such as 'order'. This is extremely useful
// the is_main_query makes sure you don't indiscriminantly filter secondary loops as well.
if ( !is_admin() && is_post_type_archive('book') && $query->is_main_query() ) {
$query->set( 'posts_per_page', '20' );
}
}
@josephhinson
josephhinson / pageorblogwidget.php
Created December 6, 2013 16:30
Widget that allows users to pull featured image and link for either a selected page, or the latest blog post. I wrote this for a custom homepage widget, but it might be useful for something else later -- especially the per-page functionality.
<?php
// This is a widget for Homepage Widgets
// initializes the widget on WordPress Load
add_action('widgets_init', 'homepage_widget_init_widget');
// Should be called above from "add_action"
function homepage_widget_init_widget() {
register_widget( 'HomepageWidget' );
}
@josephhinson
josephhinson / login_wl_memberlevels
Created May 20, 2015 20:03
Wishlist Member Levels and Login Form
<?php ?>
<div class="member-login">
<?php if (is_user_logged_in()):
$loggedin = true;
$user = wp_get_current_user();
$levels = WLMAPI::GetUserLevels($user->ID);
$getlevels = WLMAPI::GetLevels();
endif; ?>
<a class="button" href="javascript:void(null);" onclick="jQuery('.dropdown-box').toggle();">
<?php if ($loggedin): ?>
@josephhinson
josephhinson / remote_folder_rewrite
Last active September 18, 2015 01:25
serve wp-uploads from production in dev htaccess
RewriteEngine On
RewriteBase /wp-content/uploads/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^tempurl.com$
RewriteRule ^(.+)$ http://siteurl.com/wp-content/uploads/$1 [L,R=301,NE]