__('Menu Principal', 'newstc'),
'footer' => __('Menu do Rodapé', 'newstc'),
));
// Suporte a widgets
add_theme_support('widgets');
add_theme_support('widgets-block-editor');
// Suporte a logo personalizada
add_theme_support('custom-logo', array(
'height' => 60,
'width' => 200,
'flex-height' => true,
'flex-width' => true,
));
// Suporte a wide alignment no editor
add_theme_support('align-wide');
// Suporte a estilos do editor
add_theme_support('editor-styles');
add_editor_style('assets/css/editor-style.css');
// Suporte a core block patterns
add_theme_support('core-block-patterns');
// Remover estilos padrão da galeria
add_filter('use_default_gallery_style', '__return_false');
}
endif;
add_action('after_setup_theme', 'newstc_setup');
// Enfileirar scripts e estilos
function newstc_scripts() {
// Estilo principal
wp_enqueue_style('newstc-style', get_stylesheet_uri(), array(), NEWSTC_VERSION);
// Google Fonts
wp_enqueue_style('newstc-google-fonts', 'https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap', array(), null);
// Font Awesome
wp_enqueue_style('newstc-font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css', array(), '6.4.0');
// Script principal
wp_enqueue_script('newstc-script', NEWSTC_TEMPLATE_URI . '/assets/js/main.js', array(), NEWSTC_VERSION, true);
// Adiciona dados para scripts
wp_localize_script('newstc-script', 'newstc_ajax', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('newstc_nonce')
));
}
add_action('wp_enqueue_scripts', 'newstc_scripts');
// Registrar áreas de widgets
function newstc_widgets_init() {
register_sidebar(array(
'name' => __('Sidebar Principal', 'newstc'),
'id' => 'sidebar-1',
'description' => __('Widgets que aparecem na sidebar principal.', 'newstc'),
'before_widget' => '',
'before_title' => '
',
));
register_sidebar(array(
'name' => __('Rodapé - Coluna 1', 'newstc'),
'id' => 'footer-1',
'description' => __('Widgets que aparecem na primeira coluna do rodapé.', 'newstc'),
'before_widget' => '',
'before_title' => '',
));
register_sidebar(array(
'name' => __('Rodapé - Coluna 2', 'newstc'),
'id' => 'footer-2',
'description' => __('Widgets que aparecem na segunda coluna do rodapé.', 'newstc'),
'before_widget' => '',
'before_title' => '',
));
register_sidebar(array(
'name' => __('Rodapé - Coluna 3', 'newstc'),
'id' => 'footer-3',
'description' => __('Widgets que aparecem na terceira coluna do rodapé.', 'newstc'),
'before_widget' => '',
'before_title' => '',
));
}
add_action('widgets_init', 'newstc_widgets_init');
// Funções personalizadas
function newstc_post_meta() {
$reading_time = newstc_reading_time();
echo '';
echo ' ' . get_the_date() . '';
echo ' ' . esc_html($reading_time) . '';
echo '
';
}
function newstc_reading_time() {
$content = get_post_field('post_content', get_the_ID());
$word_count = str_word_count(strip_tags($content));
$reading_time = ceil($word_count / 200); // Média de 200 palavras por minuto
if ($reading_time < 1) {
return __('Menos de 1 min de leitura', 'newstc');
}
$time_string = sprintf(_n('%s min de leitura', '%s min de leitura', $reading_time, 'newstc'), $reading_time);
return $time_string;
}
function newstc_quick_access_buttons() {
$buttons = array(
array(
'icon' => 'fas fa-newspaper',
'title' => __('Notícias', 'newstc'),
'description' => __('Acesse todas as notícias da empresa', 'newstc'),
'link' => get_permalink(get_option('page_for_posts'))
),
array(
'icon' => 'fas fa-calendar-alt',
'title' => __('Eventos', 'newstc'),
'description' => __('Confira nosso calendário de eventos', 'newstc'),
'link' => '#calendar'
),
array(
'icon' => 'fas fa-users',
'title' => __('Equipe', 'newstc'),
'description' => __('Conheça nossa equipe de colaboradores', 'newstc'),
'link' => '#team'
),
array(
'icon' => 'fas fa-info-circle',
'title' => __('Sobre', 'newstc'),
'description' => __('Saiba mais sobre nossa empresa', 'newstc'),
'link' => '#about'
)
);
echo '';
}
// Função para botões de compartilhamento social
function newstc_social_share() {
$post_url = urlencode(get_permalink());
$post_title = urlencode(get_the_title());
$social_links = [
'facebook' => 'https://www.facebook.com/sharer/sharer.php?u=' . $post_url,
'twitter' => 'https://twitter.com/intent/tweet?text=' . $post_title . '&url=' . $post_url,
'linkedin' => 'https://www.linkedin.com/shareArticle?mini=true&url=' . $post_url . '&title=' . $post_title,
'whatsapp' => 'https://api.whatsapp.com/send?text=' . $post_title . ' ' . $post_url,
'instagram' => 'https://www.instagram.com', // O Instagram não tem URL de compartilhamento direto. Este link pode ser alterado para o perfil da empresa.
];
echo '';
echo '
' . esc_html__('Compartilhar:', 'newstc') . '';
echo '
';
}
// Shortcodes personalizados
function newstc_calendar_shortcode($atts) {
$atts = shortcode_atts(array(
'show_title' => true,
'show_navigation' => true
), $atts);
ob_start();
?>
5,
'show_title' => true
), $atts);
ob_start();
?>
is_main_query()) {
if ($query->is_home() || $query->is_front_page()) {
$query->set('posts_per_page', 6);
}
}
}
add_action('pre_get_posts', 'newstc_optimize_queries');
// Adicionar suporte a WebP
function newstc_webp_support($mimes) {
$mimes['webp'] = 'image/webp';
return $mimes;
}
add_filter('mime_types', 'newstc_webp_support');
// Customizar a pesquisa
function newstc_search_filter($query) {
if ($query->is_search && !is_admin()) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts', 'newstc_search_filter');
// Adicionar suporte a lazy loading para imagens
function newstc_lazy_load_images($content) {
if (is_feed() || is_admin()) {
return $content;
}
$content = preg_replace_callback('/
]+/', function($matches) {
$img = $matches[0];
// Skip if already has lazy loading
if (strpos($img, 'loading=') !== false) {
return $img;
}
// Add loading="lazy" attribute
$img = preg_replace('/
/i', '
', $img);
return $img;
}, $content);
return $content;
}
add_filter('the_content', 'newstc_lazy_load_images');
// Adicionar schema markup para melhor SEO
function newstc_schema_markup() {
if (is_single()) {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'NewsArticle',
'headline' => get_the_title(),
'datePublished' => get_the_date('c'),
'dateModified' => get_the_modified_date('c'),
'author' => array(
'@type' => 'Person',
'name' => get_the_author()
),
'publisher' => array(
'@type' => 'Organization',
'name' => get_bloginfo('name'),
'logo' => array(
'@type' => 'ImageObject',
'url' => wp_get_attachment_url(get_theme_mod('custom_logo'))
)
)
);
if (has_post_thumbnail()) {
$schema['image'] = array(
'@type' => 'ImageObject',
'url' => get_the_post_thumbnail_url(),
'width' => 1200,
'height' => 630
);
}
echo '';
}
}
add_action('wp_head', 'newstc_schema_markup');
/**
* Custom Post Type para Botões de Acesso Rápido.
*/
function newstc_register_quick_access_cpt() {
$labels = array(
'name' => _x( 'Botões de Acesso Rápido', 'Post Type General Name', 'newstc' ),
'singular_name' => _x( 'Botão de Acesso Rápido', 'Post Type Singular Name', 'newstc' ),
'menu_name' => __( 'Acesso Rápido', 'newstc' ),
'name_admin_bar' => __( 'Botão de Acesso Rápido', 'newstc' ),
'archives' => __( 'Arquivos de Botões', 'newstc' ),
'attributes' => __( 'Atributos do Botão', 'newstc' ),
'parent_item_colon' => __( 'Botão Pai:', 'newstc' ),
'all_items' => __( 'Todos os Botões', 'newstc' ),
'add_new_item' => __( 'Adicionar Novo Botão', 'newstc' ),
'add_new' => __( 'Adicionar Novo', 'newstc' ),
'new_item' => __( 'Novo Botão', 'newstc' ),
'edit_item' => __( 'Editar Botão', 'newstc' ),
'update_item' => __( 'Atualizar Botão', 'newstc' ),
'view_item' => __( 'Ver Botão', 'newstc' ),
'view_items' => __( 'Ver Botões', 'newstc' ),
'search_items' => __( 'Procurar Botão', 'newstc' ),
);
$args = array(
'label' => __( 'Botão de Acesso Rápido', 'newstc' ),
'description' => __( 'Botões para a seção de acesso rápido na home.', 'newstc' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'page-attributes' ),
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'menu_icon' => 'dashicons-screenoptions',
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'capability_type' => 'page',
);
register_post_type( 'quick_access_button', $args );
}
add_action( 'init', 'newstc_register_quick_access_cpt', 0 );
/**
* Meta Box para campos extras dos botões.
*/
function newstc_quick_access_meta_box() {
add_meta_box( 'quick_access_details', __( 'Detalhes do Botão', 'newstc' ), 'newstc_quick_access_meta_box_callback', 'quick_access_button' );
}
add_action( 'add_meta_boxes', 'newstc_quick_access_meta_box' );
function newstc_quick_access_meta_box_callback( $post ) {
wp_nonce_field( 'newstc_save_quick_access_meta', 'newstc_quick_access_nonce' );
$icon = get_post_meta( $post->ID, '_button_icon', true );
$link = get_post_meta( $post->ID, '_button_link', true );
?>
Font Awesome' ); ?>