Skip to content

Instantly share code, notes, and snippets.

View saltnpixels's full-sized avatar

Eric saltnpixels

View GitHub Profile
global $wp_query;
$term = $wp_query->get_queried_object();
$title = $term->taxonomy;
//var_dump $term to see all the stuff you can get
//if its a tag we want Tag not post_tag.... its the slug...
if($title == 'post_tag'){
echo 'Tag';
}
else{
echo ucwords( $title);
@saltnpixels
saltnpixels / add_login_to_menu.php
Created November 16, 2015 18:50
adds login menu item to navigation
//add login to nav menu. wordpress example doesnt work! needed to play with it. login menu item added!
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if ($args->theme_location == 'primary') {
$loginout = '<li class="nav-menu menu-item loginout login-icon">' . wp_loginout($_SERVER['REQUEST_URI'], false ) . '</li>';
$items .= $loginout;
return $items;
}
else
@saltnpixels
saltnpixels / ajax_wp_query
Created April 10, 2016 13:15
ajax with wp_query
//put into functions
// AJAX receiver function
function get_my_ajax_stuff() {
// If there's a POST and a nonce set, verify the nonce to make sure this request is coming from the right place
if ( $_POST && isset( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'my_nonce_action' ) ) {
// Initialize
$results = array();
// Do something here to get some data (sanitize user input as needed)
$articles = new WP_Query(array(
@saltnpixels
saltnpixels / dynamic_url_nav_menu_url.php
Last active April 14, 2016 15:18
add dynamic url to menu item to wp nav menu with replacement strings
/*--------------------------------------------------------------
# add dynamic profile link to main menu. smart and simple! just do a string replace on a menu link item
# add a link item and set the url to --url-- and give it a css class of iscurrent
--------------------------------------------------------------*/
function wp_dynamic_profile_link( $menu ){
//$link may have to be changed to your current users profile or author page or whatever...
//i had a post type profile link to each user
@saltnpixels
saltnpixels / minimum_age_validation.php
Created November 21, 2016 01:13
gravity form minimum age validation
add_filter( 'gform_validation', 'profile_validation' );
function profile_validation( $validation_result ) {
$form = $validation_result['form'];
//date of birth
$dob = rgpost('input_4'); //set to date field. also set below
// this the minimum age requirement we are validating
@saltnpixels
saltnpixels / add_post_image.php
Last active November 21, 2016 01:18
map gravity form post image to a pods field
/*--------------------------------------------------------------
# Gravity forms does not let you map a post image field in a custom field
# If you use pods and you would like to be able to map a post image to a pods image field make sure:
# the post image is not featured as that would become the post thumbnail
# add a css class tot he post image field in the form of of field_pod_field_name ( must start with field_ )
--------------------------------------------------------------*/
add_action( 'gform_after_submission', 'add_pod_images', 10, 2 );
function add_pod_images( $entry, $form ) {
@saltnpixels
saltnpixels / save_upload_field_to_custom_field.php
Last active January 18, 2024 20:32
gravity form upload file to media library and use attachment ID in custom field
add_action( 'gform_after_create_post', 'gf_add_to_media_library', 10, 3 );
/**
* Save file upload fields under custom post field to the library
*
* @param $post_id The post identifier
* @param $entry The entry
* @param $form The form
*/
@saltnpixels
saltnpixels / gform_stripe_subscriptions.php
Created October 10, 2017 15:25
Gravity forms stripe cancel from front end
<?php
/**
* Payment subscriptions and updating billing and cancelling subscriptions takes place with these hooks
* We need the stripe customer user id for updating billing
* we need the entry id of subscription so we can cancel it.
*/
/**
* @param $entry
@saltnpixels
saltnpixels / wp_menu_auto_post_type.php
Created July 25, 2018 18:55
WP hierarichal menu of any post type. posts are auto added, like pages can be
//hijack menu and output a whole post type in hierarchical order.
//post type must have hierarchical order capability and menu name must match post type
//add post types for this inside $post_types below
add_filter( 'wp_get_nav_menu_items', 'cpt_auto_add_menu', 10, 3 );
function cpt_auto_add_menu( $items, $menu, $args ) {
$post_types = array( 'add_post_types', 'that_you_want' );
$menu_slug = $menu->slug;
@saltnpixels
saltnpixels / WP_local_theme_remote_db.php
Created March 6, 2019 16:22
WordPress Workflow with remote DB on local
<?php
//Working on a WordPress theme with others can be difficult if you want to use the same database, but work locally and use git for the code.
//To do this we came up with a solution that allows working with a remote DB that everyone on the team can access, while still developing locally.
//First make sure that your wp-config file is set to use the remote db:
//set the credentials for the remote DB username and table
//change DB host to be the ip of the remote server
//Example: