Skip to content

Instantly share code, notes, and snippets.

@sybrew
Last active March 28, 2017 18:45
Show Gist options
  • Save sybrew/76259675c5495f06f7441655049f03bb to your computer and use it in GitHub Desktop.
Save sybrew/76259675c5495f06f7441655049f03bb to your computer and use it in GitHub Desktop.
wpForo compat
<?php
/**
* wpForo + The SEO Framework compatibility hook.
*/
add_action( 'init', function() {
//* Only work on is_wpforo_page and when the_seo_framework is found.
if ( function_exists( 'the_seo_framework' ) && function_exists( 'is_wpforo_page' ) && is_wpforo_page() ) {
//* Fix titles.
add_filter( 'the_seo_framework_pre_add_title', function( $title, $args, $escape ) {
$wpforo_title = wpforo_meta_title( '' );
return $wpforo_title[0] ?: $title;
}, 10, 3 );
//* Fix URLs.
add_filter( 'the_seo_framework_url_path', function( $path, $id, $external ) {
if ( $external )
return $path;
return the_seo_framework()->set_url_scheme( wpforo_get_request_uri(), 'relative' );
}, 10, 3 );
/**
* Remove duplicated description issues;
* From TSF 2.9.2 the social descriptions will work correctly too (API bugfix).
*/
add_filter( 'the_seo_framework_description_args', function( $defaults, $args ) {
//* Disable internal requests only. Magic variable (i.e. do overthink it, as it will loop).
if ( empty( $args['social'] ) && empty( $args['get_custom_field'] ) )
$defaults['get_custom_field'] = false;
return $defaults;
}, 10, 2 );
//* Remove wpforo SEO
remove_action( 'wp_head', 'wpforo_add_meta_tags', 1 );
}
}, -1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment