Ago
24
2009

Limpa o header do teu blog

Desde a versão 2.5 que o WordPress implementa uma série de caracteristicas na secção <head> dos blogs com base na função wp_head. Na realidade muitos blogs não necessitam da maioria dessas funções / informação que é implementada.

Para quem não precisa dessas funções e quer limpar um pouco a secção <head> do blog pode remover algumas dessas funções utilizando a função remove_action.

Função remove_action();

A função remove_action() é utilizada para remover uma determinada função anexada a uma acção.
A sua utilização é bastante simples e permite alguma flexibilidade, contudo neste tutorial apenas irei abordar a forma de remover as funções necessárias para o efeito do tutorial.

remove_action( $tag, $function_to_add, $priority, $accepted_args );

This function removes a function attached to a specified action hook. This method can be used to remove default functions attached to a specific action hook and possibly replace them with a substitute. See also remove_filter(), add_action() and add_filter().

Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.

via WordPress codex

O código que se segue pode ser encontrado na secção referende ao gancho wp_head que se encontra no ficheiro default-filters.php dentro da pasta wp-includes:


<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://muiomuio.net/feed/" />
  <link rel="alternate" type="text/xml" title="RSS .92" href="http://muiomuio.net/feed/rss/" />
  <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="http://muiomuio.net/feed/atom/" />
  <link rel="pingback" href="http://muiomuio.net/xmlrpc.php" />

 <link rel='archives' title='August 2009' href='http://muiomuio.net/2009/08/' />
  <link rel='archives' title='July 2009' href='http://muiomuio.net/2009/07/' />

 <link rel='archives' title='June 2009' href='http://muiomuio.net/2009/06/' />
  <link rel='archives' title='May 2009' href='http://muiomuio.net/2009/05/' />
  <link rel='archives' title='April 2009' href='http://muiomuio.net/2009/04/' />
  <link rel='archives' title='March 2009' href='http://muiomuio.net/2009/03/' />
  <link rel='archives' title='February 2009' href='http://muiomuio.net/2009/02/' />
  <link rel='archives' title='January 2009' href='http://muiomuio.net/2009/01/' />
  <link rel='archives' title='December 2008' href='http://muiomuio.net/2008/12/' />
  <link rel='archives' title='November 2008' href='http://muiomuio.net/2008/11/' />
  <link rel='archives' title='October 2008' href='http://muiomuio.net/2008/10/' />

 <link rel='archives' title='September 2008' href='http://muiomuio.net/2008/09/' />
  <link rel='archives' title='August 2008' href='http://muiomuio.net/2008/08/' />
  <link rel='archives' title='July 2008' href='http://muiomuio.net/2008/07/' />
  <link rel='archives' title='June 2008' href='http://muiomuio.net/2008/06/' />
  <link rel='archives' title='May 2008' href='http://muiomuio.net/2008/05/' />
  <link rel='archives' title='April 2008' href='http://muiomuio.net/2008/04/' />
  <link rel='archives' title='March 2008' href='http://muiomuio.net/2008/03/' />
  <link rel='archives' title='February 2008' href='http://muiomuio.net/2008/02/' />
  <link rel='archives' title='January 2008' href='http://muiomuio.net/2008/01/' />

 <link rel='archives' title='December 2007' href='http://muiomuio.net/2007/12/' />
  <link rel='archives' title='November 2007' href='http://muiomuio.net/2007/11/' />
  <link rel='archives' title='October 2007' href='http://muiomuio.net/2007/10/' />
  <link rel='archives' title='September 2007' href='http://muiomuio.net/2007/09/' />
  <link rel='archives' title='August 2007' href='http://muiomuio.net/2007/08/' />
  <link rel='archives' title='July 2007' href='http://muiomuio.net/2007/07/' />
  <link rel='archives' title='June 2007' href='http://muiomuio.net/2007/06/' />
  <link rel='archives' title='May 2007' href='http://muiomuio.net/2007/05/' />
  <link rel='archives' title='April 2007' href='http://muiomuio.net/2007/04/' />

 <link rel='archives' title='March 2007' href='http://muiomuio.net/2007/03/' />
  <link rel='archives' title='February 2007' href='http://muiomuio.net/2007/02/' />
  <link rel='archives' title='January 2007' href='http://muiomuio.net/2007/01/' />
  <link rel='archives' title='December 2006' href='http://muiomuio.net/2006/12/' />
  <link rel='archives' title='November 2006' href='http://muiomuio.net/2006/11/' />
  <link rel='archives' title='October 2006' href='http://muiomuio.net/2006/10/' />

Tendo em conta que o WordPress não é apenas utilizado em blogs a maioria destas funções podem ser removidas pois são desnecessárias, contudo recomendo cuidado pois a remoção destas funções pode originar o mau funcionamento do blog sem qualquer aviso ou notificação.

O código que se segue é um exemplo de como utilizar a função remove_action() e não uma recomendação do que se deve fazer. Aconselho o leitor a testar antes de implementar para garantir o bom funcionamento do seu blog. Estes códigos removem algumas linhas de código dos templates e permitem, consequentemente, que a página carregue mais rapidamente. Devem ser incluídos no ficheiro functions.php:

remove_action( 'wp_head', 'feed_links_extra', 3 ); // Mostrar links para feeds extra como feeds de categoria, tags, etc
remove_action( 'wp_head', 'feed_links', 2 ); // Mostrar links para as feeds de posts e comentários
remove_action( 'wp_head', 'rsd_link' ); // Remove o link para o serviço de RSD, EditURI
remove_action( 'wp_head', 'wlwmanifest_link' ); // Remove o link do ficheiro de manifesto do Windows Live Writer
remove_action( 'wp_head', 'index_rel_link' ); // Remove o link de index (<link rel='index' title='MUIOMUIO.NET' href='http://muiomuio.net' />)
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // Remove o rel=prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // remove o rel=start link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Remove os links para posts relacionados adjacentes ao post actualDisplay relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Remove o WP version e Content Generator da secção head (<meta name="generator" content="WordPress 2.8.2" />)
remove_action( 'wp_head', 'wp_get_archives' ); // remove a lista de links para as páginas de arquivos

Relembro que estes códigos são apenas a titulo de exemplo e que antes de remover qualquer uma destas funções que deves testar para garantir o bom funcionamento do blog.

Para mais informação sobre a função remove_action visita a página no WordPress Codex:
http://codex.wordpress.org/Function_Reference/remove_action

Gostaste deste artigo? Recebe acesso a conteúdo exclusivo no teu email...

Subscreve a newsletter do muiomuio.net e recebe acesso a conteúdo exclusivo sobre como criar blogs de sucesso e promoções para ganhares dinheiro online. Ao subscreveres a esta newsletter o teu email será protegido e não será partilhado com outras pessoas ou entidades.

 
Opções

A tua privacidade é respeitada, podes anular a tua subscrição a qualquer momento apenas com 1 clique.

About the Author:

Front-end developer & blogger

Advertisement

More in WordPress Tutorials (45 of 129 articles)