Skip to content

Instantly share code, notes, and snippets.

View mathetos's full-sized avatar
🪐
Working on @stellarwp Stuff

Matt Cromwell mathetos

🪐
Working on @stellarwp Stuff
View GitHub Profile
@mathetos
mathetos / smart-excerpts
Last active May 17, 2016 19:43
Smart Excerpts
<?php
/*
* This asks first for a Yoast SEO meta description,
* If that's not present, then it asks for the excerpt of the post,
* If that's not present, then it strips the content
* In this case, I have an excerpt length setting in the Customizer
* Both the excerpt and content stripping, also strip shortcodes
* @author Matt Cromwell <[email protected]>
* @copyright Copyright (c) 2014, Matt Cromwell
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
@mathetos
mathetos / plugin-activation
Last active August 29, 2015 14:11
Plugin Redirect on Activation
function detect_plugin_activation( $plugin ) {
if( $plugin == 'path-to-my-plugin') {
wp_redirect("options-general.php?page=my-plugin-settings-page");
exit;
} else {}
}
add_action( 'activated_plugin', 'detect_plugin_activation', 10, 2 );
@mathetos
mathetos / custom-wordpress-feed
Created December 9, 2014 03:30
Custom WordPress RSS Feed with Featured Image Enclosure
<?php
/**
* Custom WordImpress RSS2 Feed
* Integrates Featured Image as "Enclosure"
* See http://www.rssboard.org/rss-2-0-1#ltenclosuregtSubelementOfLtitemgt
* for RSS 2.0 specs
* @package WordPress
*/
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
@mathetos
mathetos / feed-offset
Last active October 22, 2020 17:36
WordPress Custom RSS Feed with Offset
<?php
/**
* RSS2 Feed Template for displaying RSS2 Posts feed.
* Adds an offset of "1" to display all but most recent
* Full details at: https://wordimpress.com/anatomy-advanced-wordpress-blog-notification-email
* @package WordPress
*/
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
$more = 1;
@mathetos
mathetos / functions.php
Created November 5, 2014 04:39
Conditional Custom Login Redirects in WordPress
function wip_login_redirect( $url, $request, $user ){
// Define referrer
$slug = $_SERVER["REQUEST_URI"];
// Define slugs of any referrers you want here
// For example, if they page you want to target
// is www.testsite.com/hello-world
// you'll want this:
// $islogin = strpos($slug, 'hello-world');
$islogin = strpos($slug, 'log-in');
@mathetos
mathetos / ssl-for-images.php
Last active July 3, 2018 08:21
Force http/s for images in WordPress
/**
*
* Force http/s for images in WordPress
*
* Source:
* https://core.trac.wordpress.org/ticket/15928#comment:63
*
* @param $url
* @param $post_id
*
@mathetos
mathetos / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mathetos
mathetos / image-upload-field-custom-taxonomy
Created September 20, 2014 21:37
Add Image Upload Field to Custom Taxonomy
<?php
/* Add Image Upload to Series Taxonomy */
// Add Upload fields to "Add New Taxonomy" form
function add_series_image_field() {
// this will add the custom meta field to the add new term page
?>
<div class="form-field">
<label for="series_image"><?php _e( 'Series Image:', 'journey' ); ?></label>
@mathetos
mathetos / imagelens-image-class.php
Last active August 29, 2015 14:05
Change image class if meta field available
<?php
add_filter('get_image_tag_class', 'add_imagelens_frames', 0, 4);
function add_imagelens_frames($classes, $id) {
$singlelens = get_post_meta( $id, '_enable_lens', true );
if ($singlelens === 'imagelens-single') {
return $classes . ' ' . $singlelens;
} else {
@mathetos
mathetos / custom_the_content.php
Last active July 17, 2017 09:53
Adding Custom Class to the_content
<?php
//Adding custom class to posts is easy with the post_class filter
add_filter('post_class', 'custom_content_class');
function custom_content_class($classes) {
$classes[] = 'custom_class';
return $classes;
}