Funções básicas para WordPress
Algumas funções que considero básicas em qualquer theme para WordPress.
Basta adicionar qualquer um dos códigos abaixo no functions.php do seu theme. Verifique antes se não possui a função no seu arquivo functions.php pois se colocar duplicado, pode ser que gere erro no theme.
Ativar opção de thumbnail
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150 );
Esse código apenas ativa a opção de thumbnail. Ele não vai adicionar o thumbnail no seu theme. Para isso, leia esse outro tutorial.
Permitir shortcode em widgets
add_filter('widget_text', 'do_shortcode');
Remover meta tag wp_generator
remove_action('wp_head', 'wp_generator');
Se você não remover esse wp_generator fica aparecendo no código fonte do seu theme uma linha de código dizendo qual versão do WordPress você está usando.
Acho inútil isso ficar aparecendo, sem contar que deixa seu blog vunerável para possíveis ataques de hackers.
Remover CSS padrão da Galeria
add_filter('gallery_style', create_function( '$css', 'return preg_replace("#<style type=\'text/css\'>(.*?)</style>#s", "", $css);' ) );
add_shortcode('wp_caption', 'fixed_img_caption_shortcode');
add_shortcode('caption', 'fixed_img_caption_shortcode');
function fixed_img_caption_shortcode($attr, $content = null) { $output = apply_filters('img_caption_shortcode', '', $attr, $content); if ( $output != '' ) return $output; extract(shortcode_atts(array( 'id'=> '', 'align' => 'alignnone', 'width' => '', 'caption' => ''), $attr)); if ( 1 > (int) $width || empty($caption) ) return $content; if ( $id ) $id = 'id="' . esc_attr($id) . '" '; return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '">' . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>'; }
Esse código também remove o style padrão adicionado em imagem com caption.
Remover barra do topo na visualização do blog
show_admin_bar(false);
add_filter('show_admin_bar', '__return_false');
Eu tenho horror a quase todas barras no topo (ou rodapé).
Remover CSS padrão do widget “Comentários Recentes”
function dld_remove_recent_comments_style() { add_filter( 'show_recent_comments_widget_style', '__return_false' ); }
add_action( 'widgets_init', 'dld_remove_recent_comments_style' );
Ativar sidebar
function dldblog_widgets_init() {
/* Sidebar 1 */
register_sidebar( array(
'id' => 'sidebar-1',
'name' => __('Sidebar 1', 'dld_theme'),
'description' => __('Sidebar 2', 'dld_theme'),
'before_widget' => '<!--widget--><div id="%1$s" class="widget %2$s">',
'after_widget' => "<div style=\"clear:both;\"></div> </div><!--//widget-->\n",
'before_title' => "\n<h2 class=\"title\">",
'after_title' => "</h2>\n",
) );
/* end Sidebar 1 */
}
add_action( 'widgets_init', 'dldblog_widgets_init' );
E onde quer que apareça o Sidebar 1, adicione o código abaixo:
<?php /* Sidebar 1 */ if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; /* end Sidebar 1 */ ?>
Trackbacks/Pingbacks