Having enabled Font-Awesome is a nice feature of bootScore. Somewhat frustrated , I have to add that embedding ‘own’ HTML code into a WordPress/Gutenberg block via ‘Edit as HTML’ occasionally destroys the type and content of the block : If the code is suspect to the Gutenberg editor, it replaces the work already done with an empty HTML block . Annoying if you just wanted to quickly add another icon from Font Awesome via <i class="fa-regular fa-square-check"></i>
. That must be solved differently, by a bootScore Shortcode For Font-Awesome — for example:
Solution
- Select the intended symbol from font awesome and its code.
- Insert there, where you want to get a Font Awesome Icon, directly into the Gutenberg-Editor a shortcode like
[bsfa fa-regular fa-square]
.
Background
Shortcodes are often used on WordPress to insert other elements into the Gutenberg blocks without having to use ‘Edit as HTML’. A function identifier and the required parameters are embraced by square brackets. In the file functions.php
a corresponding function is defined and made known to Gutenberg or WordPress — very important — under the selected function identifier.
That means for the Font Awesome Icons that between the opening all Font Awesome classes can be inserted which you can use in
<i class=""></i>
. The function gets them as attributes, and WordPress itself embeds the computed HTML string into the respective block.
/*
* (c) 2023 Karsten Reincke
* SPDX-License-Identifier: MIT
*/
function insert_bsfa($atts){
$atts = (array) $atts;
$vstr = "";
foreach ( $atts as $value ) {
$vstr = $vstr . " $value";
}
return '<i class="' . $vstr . '"></i>';
}
add_shortcode('bsfa', 'insert_bsfa');
Bingo.
And how does this …
… support our migration to bootScore? Well, if a web designer must abandon her current WordPress theme, she needs a replacement. A free ‘off-the-shelf’ theme, she probably wants to personalize. First a bit cosmetically, then in terms of the gray value of her pages, multilingualism and internal reference techniques and linking. Finally, she perhaps enables special footers, a secondary menu or a copyright notice before checking the SEO features of the selected theme. This is a way that this post supports too.