Title: Simplify my font selection
Last modified: August 21, 2016

---

# Simplify my font selection

 *  [studioburst](https://wordpress.org/support/users/studioburst/)
 * (@studioburst)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/simplify-my-font-selection/)
 * Hi guys, I have a very simple font selector in my theme, but I feel it could 
   be optimised using an array, but I really am struggling with getting the syntax
   correct and doubt I have come even close to achieving what I think is possible,
   can you help?
 * This is my sample code with 2 fonts:
 *     ```
       if ( get_option( 'options_selectfontheadings' ) == "Aldrich") {
       								wp_register_style( 'aldrich', get_template_directory_uri() . '/fonts/aldrich.css', array(), '20130904', 'all' );
       							} else {
       								if ( get_option( 'mediafap_selectfontheadings' ) == "Actor") {
       									wp_register_style( 'actor', get_template_directory_uri() . '/fonts/actor.css', array(), '20130904', 'all' );
       								} else {
       								}
       							}
       ```
   
 * Is it possible for those IF’s to be condensed into 1 array, so if ‘Actor’ font
   is chosen, it will load ‘actor.css’?
 * Would greatly appreciate any help here 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [ThinkUpThemes](https://wordpress.org/support/users/thinkupthemes/)
 * (@thinkupthemes)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/simplify-my-font-selection/#post-4094639)
 * Having just and ‘if else’ statement is not that bad. It’s not going to add (hardly)
   any time to the page load speed. So think it’s fine if you just want to select
   between two fonts. However, if you want to give the user the option to select
   any font from the 500+ Google Fonts database then you’ll need a more elegant 
   solution.
 * Remember to enqueue the stylesheet after it’s registered. [http://codex.wordpress.org/Function_Reference/wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script)
 * If you want to know how to expand it your font selection to the entire Google
   Font database then I can help.
 *  Thread Starter [studioburst](https://wordpress.org/support/users/studioburst/)
 * (@studioburst)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/simplify-my-font-selection/#post-4094645)
 * Thanks for replying!
 * **What if it were for 20 fonts, would that still be okay?**
 * I don’t want to offer hundreds of ill-fitting fonts, I just like to hand-pick
   fonts that meet my requirements, usually between 10-20 fonts.
 * And yes, I do enqueue the stylesheets 🙂
 *  [ThinkUpThemes](https://wordpress.org/support/users/thinkupthemes/)
 * (@thinkupthemes)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/simplify-my-font-selection/#post-4094658)
 * Ok, I’ll show you technique that I use to load Google Fonts, and you can see 
   if this works for you. Personally I think it’s a great way (but I’m bias).
 * Also, this way you’ll save time because you don’t need each stylesheet in your
   theme folder, you just pick it up from Google Fonts directly.
 *     ```
       function addgooglefonts() {
       	/* Get the font name */
       	$font = get_option( 'options_selectfontheadings' )
   
       	/* Replace white spaces with + */
       	$font = str_replace( ' ', '+', $font );
   
       	/* Get font for all possible weights */
       	wp_register_style( 'googlefont', 'http://fonts.googleapis.com/css?family=' . $font . ':300,400,600,700' );
   
       	wp_enqueue_style( 'googlefont' );
       }
       add_action( 'wp_enqueue_scripts', 'addgooglefonts', 10 );
       ```
   
 * Add this to your themes functions.php file. This will add a link to the top of
   your page in the <head> section. Check that it’s working by pressing the link
   in view source. It should take you through to the fonts stylesheet on Google.
 * If this isn’t working trying change the value of 10 upwards so that is loads 
   after your themes style.css file.
 * Good luck! Let me know how you get on.
 * Afzaal

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Simplify my font selection’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [if](https://wordpress.org/support/topic-tag/if/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 3 replies
 * 2 participants
 * Last reply from: [ThinkUpThemes](https://wordpress.org/support/users/thinkupthemes/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/simplify-my-font-selection/#post-4094658)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
