Skip to content

Instantly share code, notes, and snippets.

@selul
Created April 14, 2021 09:55
Show Gist options
  • Save selul/89557ed707541ed37120b6caa66c6eb8 to your computer and use it in GitHub Desktop.
Save selul/89557ed707541ed37120b6caa66c6eb8 to your computer and use it in GitHub Desktop.
Disable Optimole replacement on WP Rest API for Yoast Head
<?php
/*
Plugin Name: Optimole - Disable replacement on Yoast head on Rest API
Version: 0.0.1
Requires PHP: 7.0
Author URI: https://optimole.com
*/
namespace OptmlTweaks;
class RestYoastHeadIgnore {
const KEY_TO_IGNORE = 'yoast_head';
private static $buffer = null;
public function __construct() {
add_filter( 'optml_url_pre_process', function ( $response ) {
if ( ! defined( 'REST_REQUEST' ) ) {
return $response;
}
$response = json_decode( $response );
self::$buffer = $response->{self::KEY_TO_IGNORE};
unset( $response->{self::KEY_TO_IGNORE} );
return wp_json_encode( $response );
} );
add_filter( 'optml_url_post_process', function ( $response ) {
if ( ! defined( 'REST_REQUEST' ) ) {
return $response;
}
$response = json_decode( $response );
$response->{self::KEY_TO_IGNORE} = self::$buffer;
return wp_json_encode( $response );
} );
}
}
( new RestYoastHeadIgnore() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment