Extract newsletter into reusable template part and add Customizer support

This commit is contained in:
Adolfo Reyna
2026-03-13 11:32:41 -04:00
parent c05a2980bb
commit e1f4370341
4 changed files with 61 additions and 16 deletions

View File

@@ -54,21 +54,7 @@ $hero_bg = get_theme_mod('hero_background_image', get_template_directory_uri() .
</main><!-- #main --> </main><!-- #main -->
</div><!-- .container --> </div><!-- .container -->
<section class="bg-primary text-white py-5 mt-5"> <?php get_template_part('template-parts/newsletter'); ?>
<div class="container text-center py-5">
<h3 class="display-6 fw-bold mb-4 font-serif text-white">Receive weekly insights directly in your inbox.</h3>
<p class="lead mb-4 font-sans text-light">Join our community and get our latest thoughts sent straight to you.
</p>
<form class="mx-auto" style="max-width: 500px;">
<div class="input-group input-group-lg shadow">
<input type="email" placeholder="Your email address" class="form-control border-0 px-4" required>
<button type="submit" class="btn btn-secondary px-5 border-0 fw-bold text-uppercase h-100">
Subscribe
</button>
</div>
</form>
</div>
</section>
<?php <?php
get_footer(); get_footer();

View File

@@ -114,6 +114,45 @@ function wisdom1_customize_register($wp_customize)
'section' => 'wisdom1_hero_section', 'section' => 'wisdom1_hero_section',
'settings' => 'hero_background_image', 'settings' => 'hero_background_image',
))); )));
// Add Newsletter Section
$wp_customize->add_section('wisdom1_newsletter_section', array(
'title' => __('Newsletter Section', 'wisdom1'),
'priority' => 35,
));
// Newsletter Headline
$wp_customize->add_setting('newsletter_headline', array(
'default' => 'Receive weekly insights directly in your inbox.',
'sanitize_callback' => 'sanitize_text_field',
));
$wp_customize->add_control('newsletter_headline', array(
'label' => __('Headline', 'wisdom1'),
'section' => 'wisdom1_newsletter_section',
'type' => 'text',
));
// Newsletter Subheadline
$wp_customize->add_setting('newsletter_subheadline', array(
'default' => 'Join our community and get our latest thoughts sent straight to you.',
'sanitize_callback' => 'sanitize_text_field',
));
$wp_customize->add_control('newsletter_subheadline', array(
'label' => __('Subheadline', 'wisdom1'),
'section' => 'wisdom1_newsletter_section',
'type' => 'textarea',
));
// Newsletter Button Text
$wp_customize->add_setting('newsletter_button_text', array(
'default' => 'Subscribe',
'sanitize_callback' => 'sanitize_text_field',
));
$wp_customize->add_control('newsletter_button_text', array(
'label' => __('Button Text', 'wisdom1'),
'section' => 'wisdom1_newsletter_section',
'type' => 'text',
));
} }
add_action('customize_register', 'wisdom1_customize_register'); add_action('customize_register', 'wisdom1_customize_register');

View File

@@ -111,5 +111,7 @@ get_header(); ?>
<?php endwhile; // End of the loop. ?> <?php endwhile; // End of the loop. ?>
</main><!-- #main --> </main><!-- #main -->
<?php get_template_part('template-parts/newsletter'); ?>
<?php <?php
get_footer(); get_footer();

View File

@@ -0,0 +1,18 @@
<section class="bg-primary text-white py-5 mt-5">
<div class="container text-center py-5">
<h3 class="display-6 fw-bold mb-4 font-serif text-white">
<?php echo esc_html(get_theme_mod('newsletter_headline', 'Receive weekly insights directly in your inbox.')); ?>
</h3>
<p class="lead mb-4 font-sans text-light">
<?php echo esc_html(get_theme_mod('newsletter_subheadline', 'Join our community and get our latest thoughts sent straight to you.')); ?>
</p>
<form class="mx-auto" style="max-width: 500px;">
<div class="input-group input-group-lg shadow">
<input type="email" placeholder="Your email address" class="form-control border-0 px-4" required>
<button type="submit" class="btn btn-secondary px-5 border-0 fw-bold text-uppercase h-100">
<?php echo esc_html(get_theme_mod('newsletter_button_text', 'Subscribe')); ?>
</button>
</div>
</form>
</div>
</section>