Created
September 25, 2019 12:36
-
-
Save kutoi94/e9ab57af50dc5e10636349cdeb53a00a to your computer and use it in GitHub Desktop.
Create dynamic favicon with Meta Box Plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The template for displaying all single posts | |
* | |
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post | |
* | |
* @package Justread | |
*/ | |
get_header(); ?> | |
<div id="primary" class="content-area"> | |
<main id="main" class="site-main"> | |
<?php | |
while ( have_posts() ) : the_post(); | |
get_template_part( 'template-parts/content', 'single' ); | |
$favicon_site = get_site_icon_url(); | |
$favicon = rwmb_get_value('favicon', array( 'size' => 'thumbnail' )); | |
if (isset($favicon) && $favicon !== null) { | |
$favicon_url = $favicon['url']; | |
} else { | |
$favicon_url = $favicon_site; | |
} | |
the_post_navigation(); | |
// If comments are open or we have at least one comment, load up the comment template. | |
if ( comments_open() || get_comments_number() ) : | |
comments_template(); | |
endif; | |
endwhile; // End of the loop. | |
?> | |
</main><!-- #main --> | |
</div><!-- #primary --> | |
<script> | |
(function() { | |
var favicon = '<?php echo $favicon_url; ?>'; | |
var link = document.querySelector("link[rel*='icon']") || document.createElement('link'); | |
link.type = 'image/x-icon'; | |
link.rel = 'shortcut icon'; | |
link.href = favicon; | |
document.getElementsByTagName('head')[0].appendChild(link); | |
})(); | |
</script> | |
<?php | |
get_footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment