Skip to content

Instantly share code, notes, and snippets.

@VermillionOne
VermillionOne / wp_is_tree
Created August 1, 2019 22:21
Check if page or child of given ID
/**
* Check whether we are on this page or a sub page
* From WP Codex https://developer.wordpress.org/reference/functions/is_page/
*
* @param int $pid Page ID to check against.
* @return bool True if we are on this page or a sub page of this page.
*/
function wpdocs_is_tree( $pid ) { // $pid = The ID of the page we're looking for pages underneath
$post = get_post(); // load details about this page
@VermillionOne
VermillionOne / wp-placeholder-labels
Created July 18, 2019 17:19
WP - Placeholder instead of labels in Comment Forms
/**
* Change comment form textarea to use placeholder
*
* @since 1.0.0
* @param array $args
* @return array
*/
function ea_comment_textarea_placeholder( $args ) {
$args['comment_field'] = str_replace( 'textarea', 'textarea placeholder="Comment"', $args['comment_field'] );
return $args;
@VermillionOne
VermillionOne / is-custom-post-type
Created May 2, 2019 22:58
Check If Custom Post Type
/**
* Check if a post is a custom post type.
* @param mixed $post Post object or ID
* @return boolean
*/
function is_custom_post_type( $post = NULL )
{
$all_custom_post_types = get_post_types( array ( '_builtin' => FALSE ) );
// there are no custom post types
@VermillionOne
VermillionOne / gist:b525cf264bbbcaae8941ae5b5d04cb9e
Last active January 31, 2019 19:35
Display filename for custom file upload button
//For updating displayed file name for form file upload inputs - Requires jQuery
$('input[type="file"]').on('change', function(e) {
var fileSelect = e.target,
fileName = e.target.value.split(/\\|\//).pop(),
fileNameTruncated = fileName.length > 20 ? fileName.substr(0, 20) : fileName,
fileNameDisplay = fileSelect.dataset.displayfilename;
$("."+fileNameDisplay).html(fileNameTruncated+"..."+fileName.substr(fileName.length - 4));
});
@VermillionOne
VermillionOne / gulpfile.js
Created August 1, 2018 17:51 — forked from barbwiredmedia/gulpfile.js
Gulp File , sass, browser-sync, local development. Assumes folder structure /assets/styles/ & /assets/js/
var gulp = require('gulp');
var gutil = require('gulp-util');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
gulp.task('sass', function () {
gulp.src('./assets/styles/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))