• Resolved ericneuman

    (@ericneuman)


    Hello!

    I’d like to use the function echo do_shortcode in order to display a specific quiz on a custom php page.

    When I echo an HD Quiz id via the do_shortcode function, all the css formatting is gone and the result.php is displayed on a new page.

    Is there any way to fix this? Or I should try something on my functions.php?

    I know this is a very specific question and using do_shortcode is sometimes considered bad practice, but I would really appreciate any help.

    Many thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Harmonic Design

    (@harmonic_design)

    Hi ericneuman,
    it’s super late here in Ontario, so I will expand this answer more tomorrow.

    When HD Quiz was first made, WordPress was very different. One of my concerns was that sites would load HD Quiz css and js on every page – even pages that do not have a quiz. Contact Form 7 and other popular plugins of the timer were HUGE abusers of this issue. Because of this HD Quiz first checks the_content() to see if the shortcode is there, and only loads the assets if the shortcode is found.

    Tomorrow, I’ll send some small and quick code to force the assets to load for you ??

    Thread Starter ericneuman

    (@ericneuman)

    Hey, thanks for the reply!

    Yeah, I was trying to figure out the plugin code and I noticed that it checks the_content() for the shortcode right at the beginning. I tried to call one of the functions of the plugin, but since I’m no expert in php this attempt was fruitless.

    By the way, HD Quiz is a great plugin and I’m very pleased with it. Congrats on the support as well. You guys rock.

    It’s getting late here in Sao Paulo as well. You should get some rest, of course =P
    See you later

    Plugin Author Harmonic Design

    (@harmonic_design)

    Hi ericneuman,
    first, what version of HD Quiz are you using? Just because I’m pretty sure that if you are using HD Quiz v1.5 or higher, this shouldn’t have been an issue for you.

    Please add the one of the following to your theme’s functions.php file.

    If using HD Quiz v1.5+

    
    function print_hdquiz($quizID)
    {
        $quizID = intval($quizID);
        wp_enqueue_style(
            'hdq_admin_style',
            plugins_url().'/hd-quiz/css/hdq_style.css'
        );
        wp_enqueue_script(
            'hdq_admin_script',
            plugins_url()."/hd-quiz/js/hdq_script.js",
            array('jquery'),
            '1.0',
            true
        );
        echo do_shortcode('[HDquiz quiz = "'.$quizID.'"]');
    }
    

    If using HD Quiz < v1.5

    
    function print_hdquiz($quizID)
    {
        $quizID = intval($quizID);
        wp_enqueue_style(
            'hdq_admin_style',
            plugins_url().'/hd-quiz/admin.css'
        );
        wp_enqueue_script(
            'hdq_admin_script',
            plugins_url()."/hd-quiz/custom.js",
            array('jquery'),
            '1.0',
            true
        );
        echo do_shortcode('[HDquiz quiz = "'.$quizID.'"]');
    }
    

    and then you can display the quiz on anywhere in your theme by using
    <?php print_hdquiz($quizID); ?> where $quizID is the… quiz id ??

    Thread Starter ericneuman

    (@ericneuman)

    Hi again!

    I’m using an older version, 1.4.1. I should have updated it to the newest version, my mistake, sorry.

    Since I’ve got a custom code that I added to result.php in the past, I will stick to the 1.4, at least for now before updating.

    I tried the code that you’ve sent aimed at my version and it works wonderfully!

    Thank you very much for your assistance!
    Have a nice day

    Plugin Author Harmonic Design

    (@harmonic_design)

    Any time!

    and I’d wait for the next release of HD Quiz before you update.

    The next version will include a custom hook on quiz completion, meaning you will be able to run any function you want. This way you can add the function to your theme, and never have to worry about updates overriding your custom code ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘echo a quiz via do_shortcode on a page’ is closed to new replies.