• 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!

Viewing 1 replies (of 1 total)
  • Thread Starter codejp3

    (@codejp3)

    Looking at the code within the plugin, I don’t think what I want to achieve is possible as-is.

    I’ll be modifying it to include an option to “save/serve Google font files locally” instead of always/only linking to Google for them, and then to include the URL (if “served remotely” option selected) or local file path (if “saved/served locally” option selected) as part of the values array returned by the shortcode and get_ and the_ functions.

    THEN I can grab all the info I need to be able to include the proper CSS code to make font styling set with this plugin within my PDF generation.

    It’s not just for my purposes. I can see a handful of scenarios where some people would want resources used being saved and served locally, and where having either the URL or file path to those resources being helpful when custom coding non-standard, non-wordpressy things.

    I’ll submit another pull request on GitHub once I’m done.

    • This reply was modified 2 years, 5 months ago by codejp3. Reason: few typos
Viewing 1 replies (of 1 total)
  • The topic ‘Enqueue Fonts Styles in Custom Function’ is closed to new replies.