Remover os links da JSON API no cabeçalho html

31

Alguém sabe como remover os links da API JSON do WordPress na tag de cabeçalho?

<head>
...
<link rel='https://api.w.org/' href='http://example.com/wp-json/' />
<link rel="alternate" type="application/json+oembed" href="http://example.com/wp-json/oembed/1.0/embed?url=..." />
<link rel="alternate" type="text/xml+oembed" href="http://example.com/wp-json/oembed/1.0/embed?url=..." />
</head>

Gostaria de evitar o uso de um plug-in. Se possível, existe uma maneira de removê-los com a função remove_action?

remove_action( 'wp_head', 'rsd_link' );
    
por Jordan 11.12.2015 / 00:30
fonte

2 respostas

27

Eu vejo em filters.php "add_action ('wp_head', 'rest_output_link_wp_head', 10, 0)" O que me faz pensar que isso deve fazer o truque para remover rel='https://api.w.org/' .

remove_action( 'wp_head',      'rest_output_link_wp_head'              );

O resto ... * tosse * parece estar em default-filters.php

remove_action( 'wp_head',      'wp_oembed_add_discovery_links'         );

Para remover o rest_output_link_header

remove_action( 'template_redirect', 'rest_output_link_header', 11 );

Referência

por jgraup 11.12.2015 / 00:38
fonte
23

Esta função personalizada deve ajudar a remover todos os links no cabeçalho e rodapé.

function remove_json_api () {

    // Remove the REST API lines from the HTML Header
    remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
    remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );

    // Remove the REST API endpoint.
    remove_action( 'rest_api_init', 'wp_oembed_register_route' );

    // Turn off oEmbed auto discovery.
    add_filter( 'embed_oembed_discover', '__return_false' );

    // Don't filter oEmbed results.
    remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );

    // Remove oEmbed discovery links.
    remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );

    // Remove oEmbed-specific JavaScript from the front-end and back-end.
    remove_action( 'wp_head', 'wp_oembed_add_host_js' );

   // Remove all embeds rewrite rules.
   add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );

}
add_action( 'after_setup_theme', 'remove_json_api' );

E esse snippet desativa completamente a API REST e mostra {"code":"rest_disabled","message":"The REST API is disabled on this site."} ao acessar enlace

function disable_json_api () {

  // Filters for WP-API version 1.x
  add_filter('json_enabled', '__return_false');
  add_filter('json_jsonp_enabled', '__return_false');

  // Filters for WP-API version 2.x
  add_filter('rest_enabled', '__return_false');
  add_filter('rest_jsonp_enabled', '__return_false');

}
add_action( 'after_setup_theme', 'disable_json_api' );

Isso é tudo.

    
por Jentan Bernardus 20.12.2015 / 22:09
fonte

Tags