• Resolved screamson

    (@screamson)


    Hi.
    I can’t figure it out how to pass in fonts dynamically. Whatever I put in the “fonts” parameter – it’s doesn’t work.
    If you don’t mind, please decipher the steps necessary to pass in fonts dynamically.
    json-encoded/path-to/fontfile.woff – what exactly is there to be? Link to a font file in which the text is in json format? Or need a not the link and decoded the text font?
    If you would describe in detail all the actions “fonts” parameter of shortcode – it would be amazing.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author kontur

    (@kontur)

    Hey,

    see the github documentation for more info.

    E.g.:

    [fontsampler fonts="{"woff":"json-encoded/path-to/fontfile.woff", "name":"Display name of the font", "initial":true},{"woff":"json-encoded/path-to/another-fontfile.woff", "name":"Display name of the other font", "initial":false}"]

    Does this help? Do you have a (private) link to the page where you are trying to add the shortcode, and what is the code you are using?

    Thread Starter screamson

    (@screamson)

    Hello, thanks for the quick response!
    I’m not very good at php. Here is the page where the code – http://seokitchen.ru/sdgsd/.
    Here is the source code:

    		<hr />
    		<hr />
    		<hr />
    		<?php
    		$fonts[] = array(
    		'woff' => 'http://seokitchen.ru/wp-content/uploads/2018/11/Xiomara-Script.ttf',
    		'name' => 'v',
    		'initial' => true
    		);
    		$fa = str_replace(array('[', ']'), '', htmlspecialchars(json_encode($fonts, JSON_UNESCAPED_SLASHES), ENT_NOQUOTES));
    		print_r($fa);
    		echo do_shortcode('[fontsampler fonts="'.$fa.'"]');
    		?>
    		<hr />
    		<hr />
    		<hr />

    The shortcode is simply not displayed.

    Plugin Author kontur

    (@kontur)

    Try this instead:

    $fa = substr(json_encode($fonts, JSON_UNESCAPED_UNICODE), 1, -1);

    Thread Starter screamson

    (@screamson)

    I changed that line. You can see the output of the $fa variable on the page. But the shortcode didn’t work.

    Thread Starter screamson

    (@screamson)

    Below the lines, for the test, I inserted the following code:

    $dd = 1;
    echo do_shortcode('[fontsampler id='.$dd.']');

    and it works.

    Plugin Author kontur

    (@kontur)

    Instead of:
    echo do_shortcode('[fontsampler fonts="'.$fa.'"]');

    Try:

    echo do_shortcode("[fontsampler fonts='".$fa.'"]");

    Since the $fa variable contains json that has “-quotes, it would “write out” [fontsampler fonts=”…”…”…”], so you need to use [fontsampler fonts=’…’] so that the “-quotes in the actual fonts value does not break the do_shortcode.

    Thread Starter screamson

    (@screamson)

    My God, it’s working! Thank you very, very much!
    Still, the error was in my carelessness to the code.
    Your plugin is the best and you are a great developer.
    Thank you again!

    • This reply was modified 5 years, 8 months ago by screamson. Reason: Need mark as resolved
    Plugin Author kontur

    (@kontur)

    Great that it’s working now. Passing in the json is not really an ideal solution, but for the rare cases someone wanted to programmatically pass the fonts it it works. Thanks for the review 😉

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘can’t use ‘fonts’ parameter’ is closed to new replies.