Enqueue Fonts Styles in Custom Function
-
Hello. Just a quick question about how to enqueue the necessary stylesheet code for selecteed fonts within a custom function.
I have a function that creates a PDF file from custom post types/taxonomies. It is using the DomPDF library that converts HTML to PDF.
What do I need to add to the HTML in order to actually include the CSS for the selected font styles within your plugin?
For example, within the HEAD tag, I’m including my custom stylesheet in a pretty standard fashion:
$html .= '<link type="text/css" media="dompdf" href="'.get_template_directory() .'/css/styles.css" rel="stylesheet" />';
Note that with DomPDF, I’m using a local path, not the URL.
I can get the values set within the ACF Typography fields just fine. What I can’t get it to do is actually include the CSS in order to render the font styles properly. Looking to do something like this:
$font = $page_opts['font']; // get the font field values array
$html .= '<style> @font-face { font-family: '.$font['font_family'].'; font-weight: normal; font-style: '.$font['font_style'].'; src: url('fonts/FONTFILE.EXT') format('FONTFORMAT'); } </style>';
…or get the auto-generated code that is automatically enqueued/included on front-end posts.
Thanks!
- The topic ‘Enqueue Fonts Styles in Custom Function’ is closed to new replies.