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 ) ) { |
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 ); |
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; |
View allow-links-in-excerpts.php
// Allow links in excerpts | |
function sg_trim_words( $text, $num_words, $more, $original_text ) { | |
$text = strip_tags( $original_text, '<a>' ); | |
// @See wp_trim_words in wp-includes/formatting.php | |
if ( strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { | |
$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); | |
preg_match_all( '/./u', $text, $words_array ); | |
$words_array = array_slice( $words_array[0], 0, $num_words + 1 ); | |
$sep = ''; | |
} else { |
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. |