Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Disable the "foo" custom post type feed
*
* @since 1.0.0
* @param object $query
*/
function ja_disable_cpt_feed( $query ) {
if ( $query->is_feed() && in_array( 'foo', (array) $query->get( 'post_type' ) ) ) {
die( 'Feed disabled' );
@jaredatch
jaredatch / functions.php
Created March 1, 2017 16:59
WPForms conditional form redirects
<?php
/**
* WPForms custom redirect
*
* @param string $url URL form will redirect to
* @param int $form_id Form ID
* @param array $fields Submitted form fields
* @return string
*/
function wpf_custom_redirect( $url, $form_id, $fields ) {
@jaredatch
jaredatch / gist:1337595
Created November 3, 2011 19:52
Add external link to admin menu in WordPress
<?php
/**
* Add external links to the admin menu
*/
add_action( 'admin_menu' , 'ja_new_admin_menu_items' );
function ja_new_admin_menu_items() {
global $submenu;
$url = get_bloginfo('url');
/**
@jaredatch
jaredatch / gist:aea2fe3777b490bc927b
Last active July 17, 2021 03:19
Merge secondary menu into primary for mobile
jQuery(document).ready(function($){
function mobile_combine_nav() {
$('.nav-header li.secondary-item').remove();
if ( $('.nav-secondary').css( 'display' ) == 'none' ) {
$('.nav-secondary li').addClass('secondary-item').clone().appendTo('.nav-header ul');
}
}
mobile_combine_nav();
$(window).resize(mobile_combine_nav);
});
@jaredatch
jaredatch / functions.php
Created August 26, 2016 19:34
WPForms preselect dropdown field based on URL parameter
<?php
/**
* Preselect dropdown field based on URL parameter.
*
* @param array $field
* @param array $field_atts
* @param array $form_data
* @return array
*/
function wpf_preselect_dropdown( $field, $field_atts, $form_data ) {
@jaredatch
jaredatch / wpforms-input-masks.md
Last active March 15, 2021 21:22
WPForms Input Masks

Basic Masks

Basic input masks use symbols to create the mask.

  • 9: Numeric
  • a: Alphabetical
  • A: Alphabetical (forces uppercase)
  • *: Alphanumeric
  • &: Alphanumeric (forces uppercase)
@jaredatch
jaredatch / gist:1629862
Created January 17, 2012 23:54
Remove hentry from post_class()
<?php
/**
* Remove 'hentry' from post_class()
*/
function ja_remove_hentry( $class ) {
$class = array_diff( $class, array( 'hentry' ) );
return $class;
}
add_filter( 'post_class', 'ja_remove_hentry' );
@jaredatch
jaredatch / functions.php
Created October 12, 2020 22:43
Display WPForms entries count
<?php
/**
* Custom shortcode to display WPForms form entries count for a form.
*
* Basic usage: [wpf_entries_count id="FORMID" type="TYPE"].
*
* @param array $atts Shortcode attributes.
*
* @return string
*/
@jaredatch
jaredatch / pimp-my-log-mamp-pro.md
Last active January 28, 2020 04:35
Install Pimp my Log with MAMP Pro (for use with WordPress development)

Install Pimp My Log with MAMP Pro (for use with WordPress development)

Pimp my Log

  1. Enable PHP logging in MAMP Pro, under the PHP settings (screenshot)

  2. Inside your MAMP Sites directory (or equivalent), create a new directory pimpmylog

  3. Create a new host, such as phplog.local, in MAMP for easy access (screenshot)

@jaredatch
jaredatch / gist:3764391
Last active November 8, 2019 09:48
Redirect taxonomy to use archive template
<?php
/**
* Redirect taxonomy to use custom post type archive template
*
* @author Jared Atchison
* @link http://jaredatchison.com/code/
* @param string $template
* @return string
*/
function ja_template_redirect( $template ) {