• Resolved mcho

    (@mcho)


    Hi, we were using html_output() to get all the tags generated by the SEO Framework 4.0, but it seems that the function is deprecated in 4.2 with no alternative. Should I use individual functions like get_generated_open_graph_description(), etc. to get what html_output() used to output?

    My current codes are as follows, and I was wondering how best to change them so that they are compatible with SEO Framework 4.2.

    if (function_exists(‘the_seo_framework’)) {
    ob_start();
    the_seo_framework()->html_output();
    $meta .= ob_get_contents();
    return ob_get_clean();
    }

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter mcho

    (@mcho)

    Actually, I see that the_seo_framework()->get_html_output() still works, though you said it’s deprecated here (https://theseoframework.com/changelog/4-2-0-perfect/). Is it not deprecated? Can I still use it?

    Plugin Author Sybre Waaijer

    (@cybr)

    Howdy!

    In TSF v4.2 (Nov 2021) I added tsf() as an alias of the_seo_framework().

    In TSF v4.0.5 (Mar 2020), I added tsf()->get_html_output() for convenience. Yet, in v4.2 (Nov 2021), I deprecated it in favor of directly printing the metadata (which is much faster) and removed support for deprecated filters. The method is still available for some time to ease migration from it. Using a deprecated function/method/filter will output a notification when you have WP_DEBUG enabled. I highly discourage you from implementing deprecated code, and I’m glad you reached out.

    In TSF v4.0 (Sep 2019), I marked tsf()->html_output() as private, meaning that third-party developers shouldn’t use it. Privately marked functions are prone to compatibility-breaking changes and even deletion and shouldn’t be relied upon. Changes in privately marked code also won’t make it to the changelog.

    However, supporting your use case, I will reverse the decision to mark tsf()->html_output() private, and I encourage you to use this method still.

    As of TSF v4.1.4, you could also use tsf()->do_meta_output(). But, that will bypass some tests for valid queries.

    In your first comment, the $meta .= ob_get_contents(); line does nothing impactful, and you can remove it.

    if ( function_exists( 'tsf' ) ) {
        ob_start();
        tsf()->html_output();
        return ob_get_clean();
    }

    I hope this helps ??

    • This reply was modified 2 years, 9 months ago by Sybre Waaijer. Reason: removed sketch copy
    Thread Starter mcho

    (@mcho)

    Thank you very much!

    I am composer installing this package, “wpackagist-plugin/autodescription”: “^4.2”, and I did do a fresh new composer install just now, and I don’t see that html_output() is outputting anything. Is this change in the package, yet?

    Also, I’m wondering if you had a reason to make html_output() to be private, in the first place. If so, is your decision to make it public now conflicting with your previous reasoning?

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi again!

    I made it private because I was under the assumption that no one would need it, and I was planning to rewrite the output API — this probably won’t happen anytime soon. There also are no other convenient methods to achieve your goals.

    The tsf()->html_output() method must run at a registered WordPress loop; this restriction was tightened at TSF 4.2.4, where tsf()->query_supports_seo() now checks for AJAX, Cron, JSON, and REST queries and blocks the function from outputting anything when detected.

    You may need to use tsf()->do_meta_output() instead to bypass that restriction. Please note that without knowing the exact environment of your code, I can only make assumptions.

    Thread Starter mcho

    (@mcho)

    Oh, cool. do_meta_output() worked. We are using React and WordPress as a headless CMS, so we use this function to output all the seo tags to the front end from the REST API endpoint. I hope you keep this functionality for our use case scenario. Thank you!

    Thread Starter mcho

    (@mcho)

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘What is alternative for html_output?’ is closed to new replies.