This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Redirect to Canonical | |
Description: Redirect posts to canonical URL when accessed via secondary category URL slugs. | |
Version: 1.0 | |
Author: Greg Perham | |
License: GPL2 | |
*/ | |
defined( 'ABSPATH' ) || exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'wp_constrain_dimensions', 'mcoc_constrain_dimensions', 11, 5 ); | |
function mcoc_constrain_dimensions( $dimensions, $current_width, $current_height, $max_width, $max_height ) { | |
// Stop if desired size is not post thumbnail | |
if ( ( $max_width != get_option( 'thumbnail_size_w' ) ) || ( $max_height != get_option( 'thumbnail_size_h' ) ) ) return $dimensions; | |
// Ensure cropped width is at least post thumbnail width | |
if ( $dimensions[0] >= $max_width ) return $dimensions; | |
if ( $current_height > $max_height ) { | |
return [ | |
$max_width, | |
$max_width * $current_height / $current_width |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let page builders like Elementor control the display of single events | |
function dont_let_tec_hijack( $should_hijack, $query ) { | |
if ( $query->is_single() ) $should_hijack = false; | |
return $should_hijack; | |
} | |
add_filter( 'tribe_events_views_v2_should_hijack_page_template', 'dont_let_tec_hijack', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Make BB status obvious */ | |
add_filter( 'display_post_states', 'sg_bb_post_state', 10, 2 ); | |
function sg_bb_post_state( $post_states, $post ) { | |
if ( FLBuilderModel::is_builder_enabled( $post->ID ) ) { | |
$post_states[] = 'Beaver Builder'; | |
} | |
return $post_states; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Default event recap slug | |
* If has parent and is in category Recap, set slug to "recap". | |
* Can't use `wp_insert_post_data` because taxonomy data isn't included, frustratingly. | |
*/ | |
// Catch changes in block editor | |
add_filter( 'rest_post_dispatch', 'recap_slug_rest', 10, 3 ); | |
function recap_slug_rest( $result, $server, $request ) { | |
if ( 'PUT' == $request->get_method() ) { | |
$post_id = $request->get_param( 'id' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function rlv_html_tag_boost( $content ) { | |
$weightings = [ | |
'h1' => 5, | |
'h2' => 4, | |
'h3' => 2, | |
'strong' => 1, | |
]; | |
foreach ( $weightings as $tag => $weight ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 ) ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; |
NewerOlder