Skip to content

Instantly share code, notes, and snippets.

@moxdev
Last active February 14, 2019 17:24
Show Gist options
  • Save moxdev/f6274682c55c32c6f4c4a36c6475e0f0 to your computer and use it in GitHub Desktop.
Save moxdev/f6274682c55c32c6f4c4a36c6475e0f0 to your computer and use it in GitHub Desktop.
WP Customizer Footer Logo #wp
// Add first
$wp_customize->get_setting( 'logo_icon' )->transport = 'postMessage';
// Add 2nd
/**
* Add a control to upload the Footer Logo.
* Add a setting for the site Footer Logo.
*/
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
'logo_icon',
array(
'label' => __( 'Footer Logo', 'quantum' ),
'section' => 'title_tagline',
'settings' => 'logo_icon',
'priority' => 8,
)
)
);
// Add to $wp_customize
$wp_customize->selective_refresh->add_partial(
'logo_icon',
array(
'selector' => '.ftr-logo',
'render_callback' => 'quantum_customize_partial_footer_logo',
)
);
// Add function and customize if needed
/**
* Render the footer logo for the selective refresh partial
*/
function quantum_customize_partial_footer_logo() {
$custom_icon = get_theme_mod( 'logo_icon' );
if ( $custom_icon ) {
$icon_id = attachment_url_to_postid( $custom_icon );
$logo = wp_get_attachment_image( $icon_id, 'full' ); ?>
<div class="ftr-logo">
<a rel="noopener noreferrer" href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php
echo wp_kses(
$logo,
[
'img' =>
[
'src' => true,
'srcset' => true,
'sizes' => true,
'class' => true,
'id' => true,
'width' => true,
'height' => true,
'alt' => true,
'align' => true,
],
]
);
?>
</a>
</div>
<?php
}
}
// Call function
<?php quantum_customize_partial_footer_logo(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment