1. Home
  2. Knowledge Base
  3. Text Preview for Add-Ons Ultimate
  4. Advanced Topics for Text Preview
  5. Set different fonts for each text preview field
  1. Home
  2. Knowledge Base
  3. Text Preview for Add-Ons Ultimate
  4. Set different fonts for each text preview field

Set different fonts for each text preview field

The Text Preview for Add-Ons Ultimate plugin allows you to define which fonts the user can pick from. If you would like to define different fonts for different text preview fields, you can use the snippet below.

Note a couple of things:

  • You’ll need to update the field IDs to match the IDs of your fields
  • You should list the fonts in this format: 'arial' => 'Arial'
<?php
/**
* Filter the available fonts for each text preview field
* List fonts in arrays using 'abel' => 'Abel' key / value pairs
* Update the field IDs to match your own
*/
function demo_filter_all_fonts( $all_fonts, $available_fonts, $field ) {
// Update the field IDs below to match your field IDs
if( $field['field_id'] == 1209 ) {
// Make an array of fonts for this field only
$available_fonts = array(
'abel' => 'Abel',
'arial' => 'Arial'
);
} else if( $field['field_id'] == 1307 ) {
// Make an array of fonts for this field only
$available_fonts = array(
'abel' => 'Abel',
'courier' => 'Courier'
);
}
$all_fonts = array_merge( array( 'default' => __( 'Default theme font', 'pr-advanced-previews-addons-ultimate' ) ), $available_fonts );
return $all_fonts;
}
add_filter( 'apaou_all_fonts', 'demo_filter_all_fonts', 10, 3 );

Here’s how to add the snippet.

Was this article helpful?

Related Articles