Skip to content

Instantly share code, notes, and snippets.

Avatar

Greg Perham swinggraphics

  • Swing Graphics
  • Northampton, MA
View GitHub Profile
View prefer-pages-over-cpt.php
/* Prefer Pages over CPT */
function sg_page_before_cpt( $query ) {
$cpt_slug = 'my_cpt_slug';
$cpt_rewrite_slug = 'my_cpt_rewrite_slug';
if( isset( $query->query_vars[$cpt_slug] ) && $slug = $query->query_vars[$cpt_slug] ) {
$slug = "$cpt_rewrite_slug/$slug";
if( get_page_by_path( $slug ) ) {
@swinggraphics
swinggraphics / avoid-duplicate-posts.php
Created Dec 11, 2020
Exclude posts that have been displayed already by setting `avoid_duplicates` query var
View avoid-duplicate-posts.php
// Based on code from https://ashton.codes/avoid-showing-wordpress-post-multiple-loops/
function sg_track_displayed_posts( $permalink, $post ) {
global $sg_displayed_posts;
$sg_displayed_posts[ $post->post_type ][] = get_the_ID();
return $permalink;
}
add_filter( 'post_link', 'sg_track_displayed_posts', 10, 2 );
add_filter( 'post_type_link', 'sg_track_displayed_posts', 10, 2 );
@swinggraphics
swinggraphics / oxy-save-rendered-content.php
Last active Nov 19, 2020
Copy compiled Oxygen page content to post_content for search
View oxy-save-rendered-content.php
/* Copy compiled Oxygen page content to post_content for search */
function sg_save_rendered_page_content( $meta_id, $object_id, $meta_key, $meta_value ) {
// Debugging
// $debug .= preg_replace( '#(\[/[^\]]+?\])#', "$1\n", $meta_value );
// file_put_contents( plugin_dir_path( __FILE__ ) . 'debug.html', $debug );
if ( 'ct_builder_shortcodes' != $meta_key ) return;
// Don't try to render anything with inner content
if ( false !== strpos( $meta_value, '[ct_inner_content' ) ) return;
@swinggraphics
swinggraphics / oxygen-pro-menu-tap-sub-menu.js
Created Nov 2, 2020
Activate Pro Menu desktop dropdowns on tap
View oxygen-pro-menu-tap-sub-menu.js
$('document').ready(function(){
/* Activate Pro Menu desktop dropdowns on tap */
$('.oxy-pro-menu-list .menu-item-has-children > a').on('touchstart', function(event){
var $this = $(this);
if ( $this.parents('.oxy-pro-menu-off-canvas-container, .oxy-pro-menu-open-container').length ) return;
event.preventDefault();
event.stopPropagation();
$('body').trigger('touchstart.mouseout');
$this.parent().trigger('mouseenter');
@swinggraphics
swinggraphics / allow-links-in-excerpts.php
Created Jun 7, 2018
WordPress strips out tags in `wp_trim_words()`, which is called by `get_the_excerpt()`; so we have to filter 'wp_trim_words', basically copying that function with one change: replace `wp_strip_all_tags()` with `strip_tags()`. We don't want other functions that run `wp_trim_words` to be modified, so we add our filter while `get_the_excerpt()` is …
View allow-links-in-excerpts.php
@swinggraphics
swinggraphics / broadcast-replace-site_url.php
Created May 14, 2018
Replace site_url in posts syndicated by WP Broadcast
View broadcast-replace-site_url.php
<?
/**
* Hook into Broadcast
* Modify links in the broadcasted post content
* "Replace Site URL" checkbox appears in child post meta box to show if this was applied
*/
add_action( 'threewp_broadcast_prepare_meta_box', 'my_custom_prepare_meta_box' );
function my_custom_prepare_meta_box( $action ) {
$meta_box_data = $action->meta_box_data; // Convenience.