Skip to content

Instantly share code, notes, and snippets.

View mrwweb's full-sized avatar

Mark Root-Wiley mrwweb

View GitHub Profile
@mrwweb
mrwweb / truncate_html_string.php
Created July 3, 2014 18:08
Improved version of text-truncating html string function to improve character count accuracy. Code found on oikos.org.uk/2013/02/tech-notes-a-wordpress-excerpt-with-html-tags/.
<?
/**
* Truncates text.
*
* Cuts a string to the length of $length and replaces the last characters
* with the ending if the text is longer than length.
*
* See: oikos.org.uk/2013/02/tech-notes-a-wordpress-excerpt-with-html-tags/
* See also: wpengineer.com/2410/dont-use-strlen/
* See also also: oikos.org.uk/2013/02/tech-notes-a-wordpress-excerpt-with-html-tags/#comment-1467093876
@mrwweb
mrwweb / fpw_image_size_filter_examples.php
Last active August 29, 2015 14:06
Feature a Page Widget 2.0 Filter Examples
See: https://gist.github.com/56edda993e0b7062c7af
@mrwweb
mrwweb / content-taxonomy-head.php
Last active August 29, 2015 14:06
These three files should go in a child theme of the WP Advocate theme if using the People Profile CPT to show individual People Category taxonomy archive pages
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header clearfix">
<h1 class="entry-title"><?php echo single_term_title(); ?></h1>
</header><!-- .entry-header -->
<?php
$term_description = term_description();
if( $term_description ) : ?>
<div class="entry-content post-content">
@mrwweb
mrwweb / fpw_image_size_filter_examples.php
Last active August 29, 2015 14:06
Example of fpw_image_size filter in Feature a Page Widget 2.0. By default, Feature a Page Widget registers three sizes, one for each layout: fpw_big, fpw_square, fpw_banner. NOTE: To produce consistent image sizes and a good widget layout, CSS rules like max-width may at times affect the image's apparent size on the front end.
<?php
/**
* replace one of the widget image sizes
*
* examples replaces the banner layout's image with the 'large' size image from Settings > Media
*
* If you replacing $size with a custom image size, you must register that separately with add_image_size()
*
* @param $size string slug of registered image size
* @return string|array slug of registered image size or "array( width, height )" (not recommended)
@mrwweb
mrwweb / fpw_post_types_filter_examples.php
Last active August 29, 2015 14:06
Examples of the fpw_post_types filter in Feature a Page Widget 2.0. By default, the widget will allow Pages and Posts to be featured.
<?php
/**
* add a post type that can be featured in the Feature a Page Widget
*
* Any post types added via this filter automatically have support added for excerpts and featured images
*
* This example adds the ability to feature the "book" post type
*
* @param $post_types array array of post_type slugs that can be featured with the widget
*/
@mrwweb
mrwweb / fpw_read_more_text_filter_examples.php
Created September 22, 2014 18:27
Example of the fpw_read_more_text filter in Feature a Page Widget 2.0. The widget uses an accessible "read more" link that says in full "Read More about {Page Title}..." to screen readers, search engines, etc. but only appears as "Read More..." The filter only modifies the visible portion of the link.
<?php
/**
* modify the "Read More" text in the accessible "Read More" link
*
* example: change it to "Continue Reading"
*
* @param $read_more_text string The "________" in "________ about {Page Title}"
*/
function fpw_change_read_more( $read_more_text ) {
$read_more_text = __( 'Continue Reading', 'your-text-domain' );
@mrwweb
mrwweb / fpw_widget_templates_filter_examples.php
Last active August 29, 2015 14:06
Example of fpw_widget_templates filter in Feature a Page Widget 2.0. Allows remove of default layouts, "registering" of custom layouts, or setting one layout for all widget instances.
<?php
/**
* remove a default template
*
* default templates are: big, banner, wrapped
*
* this example removes the "Big Image" template
*
* @param $templates array slug => label pairs of templates
*/
@mrwweb
mrwweb / fpw_auto_excerpt_filter_example.php
Created September 22, 2014 18:34
Example of fpw_auto_excerpt filter in Feature a Page Widget 2.0. By default, the widget only shows the excerpt for posts with an explicitly-set excerpt (i.e. has_excerpt() is TRUE).
<?php
/**
* Set fpw_auto_excerpt to TRUE to allow auto-generated excerpts if the Excerpt field is blank
*
* Uses the_excerpt() and associated filters.
*/
add_filter( 'fpw_auto_excerpt', '__return_true' );
@mrwweb
mrwweb / bar.php
Created September 25, 2014 22:37
"Disabliing AJAX" in Event Views (List, Month, etc.) in The Event Calendar by Modern Tribe
<?php
/**
* Events Navigation Bar Module Template
* Renders our events navigation bar used across our views
*
* Override this template in your own theme by creating a file at [your-theme]/tribe-events/modules/bar.php
*
* $filters and $views variables are loaded in and coming from
* the show funcion in: lib/tribe-events-bar.class.php
*
@mrwweb
mrwweb / functions.php
Created November 3, 2014 22:54
Move "Add to iCal / Google" links below event information in Modern Tribe's The Events Calendar plugin.
<?php
remove_filter('tribe_events_single_event_after_the_content', array('TribeiCal', 'single_event_links'), 10, 1);
add_filter( 'tribe_events_single_event_after_the_meta', array('TribeiCal', 'single_event_links'), 10, 1);