Skip to content

Commit

Permalink
Merge pull request #46 from Automattic/aaronjbap/show-header-toggle
Browse files Browse the repository at this point in the history
Add Show Header Image toggle
  • Loading branch information
aaronjbaptiste authored Nov 29, 2024
2 parents 0922e89 + fc7a4b5 commit d4d0f01
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
10 changes: 7 additions & 3 deletions includes/block-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,20 +635,24 @@ function tumblr3_block_haspages( $atts, $content = '' ): string {
* @return string
*/
function tumblr3_block_showheaderimage( $atts, $content = '' ): string {
return ( 'remove-header' !== get_theme_mod( 'header_image', 'remove-header' ) ) ? tumblr3_do_shortcode( $content ) : '';
return ( get_theme_mod( 'show_header_image', true ) &&
'remove-header' !== get_theme_mod( 'header_image', 'remove-header' ) )
? tumblr3_do_shortcode( $content ) : '';
}
add_shortcode( 'block_showheaderimage', 'tumblr3_block_showheaderimage' );

/**
* Rendered if you have "Show header image" disabled.
* Rendered if you have "Show header image" disabled.
*
* @param array $atts The attributes of the shortcode.
* @param string $content The content of the shortcode.
*
* @return string
*/
function tumblr3_block_hideheaderimage( $atts, $content = '' ): string {
return ( 'remove-header' === get_theme_mod( 'header_image', 'remove-header' ) ) ? tumblr3_do_shortcode( $content ) : '';
return ( ! get_theme_mod( 'show_header_image', true ) ||
'remove-header' === get_theme_mod( 'header_image', 'remove-header' ) )
? tumblr3_do_shortcode( $content ) : '';
}
add_shortcode( 'block_hideheaderimage', 'tumblr3_block_hideheaderimage' );

Expand Down
19 changes: 19 additions & 0 deletions src/Customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ public function global_options( $wp_customize ): void {
)
);

// Add a show header image checkbox control.
$wp_customize->add_setting(
'show_header_image',
array(
'default' => 'yes',
'sanitize_callback' => 'sanitize_text_field',
)
);

$wp_customize->add_control(
'show_header_image',
array(
'label' => __( 'Show Header Image', 'tumblr3' ),
'section' => 'tumblr3_boolean',
'type' => 'checkbox',
'priority' => 10,
)
);

// Add a stretch header image checkbox control.
$wp_customize->add_setting(
'stretch_header_image',
Expand Down

0 comments on commit d4d0f01

Please sign in to comment.