Skip to content

Instantly share code, notes, and snippets.

View corypina's full-sized avatar

Cory Piña corypina

View GitHub Profile
@corypina
corypina / page-resize.js
Last active March 31, 2021 17:51
Keep the footer pinned to the bottom of the page, even when content isn't tall enough.
/* Be sure to set your element queries according
to what you actually have in the document! */
(function ($) {
// Bind to the resize event of the window object
const doResize = () => {
let wpadmin = 0;
if ($("#wpadminbar").length) { // in case WP admin bar is present
wpadmin = $("#wpadminbar").height();
@corypina
corypina / post-type-current-menu-item.php
Created March 5, 2021 06:18
Add "current" class to post type archive menu items when viewing single
<?php
/*
Give the "current-menu-item" class to archive links
in the menu when viewing singles of the post type.
1. Add the post type archive page to the menu (NOT as a custom link)
2. Add this filter.
*/
@corypina
corypina / no-subscribers-in-admin.php
Created September 30, 2020 17:09
Prevent Subscribers from accessing wp-admin
<?php
// If users have multiple roles, refactor line 7 to check for required
// roles instead of rejecting Subscribers
add_action( 'init', function () {
if ( is_admin()
&& in_array( 'subscriber', (array) $user->roles )
&& ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
) { wp_redirect( '/' ); exit; }
@corypina
corypina / content-minimum-height.js
Last active July 17, 2020 23:11
Min-height for main content area
// Calculate
(function ($) {
// Bind to the resize event of the window object
$(window)
.on("resize", function () {
let wpadmin;
if ($("#wpadminbar")) { // in case WP admin bar is present
wpadmin = $("#wpadminbar").height();
} else {
@corypina
corypina / wp-show-current-template.php
Created June 4, 2020 19:37
Show current WP template in use
<?php
// Show the current template in use
// To use, add ?show-template to URL
add_action('wp_head', 'show_template_filename');
function show_template_filename() {
if ( isset($_GET['show-template']) ) {
global $template;
echo '<span style="background-color: #ooo;color: #fff;">';
@corypina
corypina / webhook-reception-test.php
Created June 4, 2020 19:35
Test webhook content
<?php
// Test webhook reception
echo "Checking for webhook";
$webhookContent = "";
$myfile = fopen("./webhook.log", "a") or die("Unable to open file!");
$webhook = fopen('php://input' , 'rb');
while (!feof($webhook)) {
@corypina
corypina / hide-taxonomy-term.php
Last active May 20, 2020 05:16
Use a custom taxonomy term to hide posts from main queries
<?php
// Hide custom taxonomy term from all queries
// Still accessible via direct link
add_action('pre_get_posts', function($query){
if ( $query->is_home() || $query->is_feed() || $query->is_search() || $query->is_archive() ) {
$tax_query = array(
array(
'taxonomy' => 'admin_category', // taxonomy name
add_shortcode('SHORTCODE', function($atts){
$defaults = array();
$atts = wp_parse_args( $atts, $defaults );
ob_start();
// Do Stuff
return ob_get_clean();
});
@corypina
corypina / auto-year-shortcode.php
Created January 6, 2020 23:59
Auto Year WordPress shortcode
<?php
// Generates the current year, for use in copyright notices
// Call with [auto-year]
// e.g., © [auto-year] Your Name
add_shortcode('auto-year', function(){
$year = date('Y');
return $year;
});
@corypina
corypina / show-post-id.php
Created September 9, 2019 20:51
Show the current post ID when in the WordPress admin edit screen
<?php
// Prominently display the post ID in as an admin notice
add_action( 'admin_notices', function(){
global $post;
if ( isset($_GET['post']) ) {
$class = 'notice notice-error';
$id = $post->ID;
$message = __( 'Post ID: ' . $id );