css - Use php to identify duplicate settings -


i building wordpress theme, in theme customizer can choose google fonts body text, headings , navbar.

below shows how importing fonts chosen custom-css.php file called in head of page:

$base_font = get_theme_mod('font_base_family'); $headers_font = get_theme_mod('font_headings_family'); $menu_font = get_theme_mod('font_nav_family');  if($base_font !='') { ?> <link href='http://fonts.googleapis.com/css?family=<?php echo str_replace(" ","+",$base_font );?>:100,200,300,400,500,600,700,800,900' rel='stylesheet' type='text/css'> <?php } ?>   <?php if ($headers_font != '') { ?> <link href='http://fonts.googleapis.com/css?family=<?php echo str_replace(" ","+",$headers_font );?>:100,200,300,400,500,600,700,800,900' rel='stylesheet' type='text/css'> <?php } ?>  <?php if ($menu_font != '') { ?> <link href='http://fonts.googleapis.com/css?family=<?php echo str_replace(" ","+",$menu_font );?>:100,200,300,400,500,600,700,800,900' rel='stylesheet' type='text/css'> <?php } ?> 

then later down in custom-css.php file have (shortened):

body { font-family: <?php echo get_theme_mod('font_base_family'); ?>; } h1, h2, h3, h4, h5, h6 { font-family: <?php echo get_theme_mod('font_headings_family'); ?>; } #header nav ul li > a, #header nav ul li > span { font-family: <?php echo get_theme_mod('font_nav_family'); ?>; } 

the issue have loading 3 fonts this, font weights too, drastically increases page load time. if user wants 3 differents fonts each, that's fine, decide have 2 or 3 of same fonts, don't want have duplicates in head.

say example wants same font body , headings, there way can, using php, "if same b or c - remove duplicate"

hope makes sense.

assign fonts array keys , iterate it.

$fonts = array(     get_theme_mod('font_base_family') => 'base',     get_theme_mod('font_headings_family') => 'headings',     get_theme_mod('font_nav_family') => 'nav' );  foreach ($fonts $key => $type) { ?>     <link href='http://fonts.googleapis.com/css?family=<?php echo str_replace(" ", "+", $key); ?>:100,200,300,400,500,600,700,800,900' rel='stylesheet' type='text/css'> <?php } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -