Support » Plugin: Yoast SEO » JavaScript error being thrown when hiding Yoast CPT metabox

  • Resolved yikesitskevin



    We’re using the latest version (v5.0.2) of Yoast (and WP 4.8) and working on a new site for a client.

    We’re using a snippet to remove the Yoast metabox from some of our Custom Post Types. This is the snippet (the name of the CPT in this instance is gbs_ecommunicator).

    /** Hide Yoast SEO metabox **/
    function remove_yoast_from_gbs_ecommunicator() {
    	remove_meta_box( 'wpseo_meta' , 'gbs_ecommunicator' , 'normal' );
    add_action( 'add_meta_boxes' , 'remove_yoast_from_gbs_ecommunicator', 11 );

    Recently we’ve noticed a JavaScript error is being thrown on the CPTs that are using this snippet. Here is the JavaScript error:

    Uncaught Error: The snippet preview requires a valid target element
        at new F (wp-seo-post-scraper-502.min.js:38)
        at Object.f [as create] (wp-seo-post-scraper-502.min.js:1)
        at c (wp-seo-post-scraper-502.min.js:1)
        at HTMLDocument.G (wp-seo-post-scraper-502.min.js:1)
        at i (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,jquery-ui-core,utils,jquery-ui-widget,jquery…:2)
        at Object.fireWith [as resolveWith] (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,jquery-ui-core,utils,jquery-ui-widget,jquery…:2)
        at Function.ready (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,jquery-ui-core,utils,jquery-ui-widget,jquery…:2)
        at HTMLDocument.K (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,jquery-ui-core,utils,jquery-ui-widget,jquery…:2)

    It appears the Yoast metabox JS is still active on the page and is throwing an error when it can’t find the metabox it’s trying to target. Is there a new, better way to remove the metabox? Should I also be dequeue’ing the JavaScript file?

    This error is, for example, breaking the editor’s quicktags buttons (the tooltip for the editor’s ‘text’ tab). I am not sure when this error arose.


    P.S. We have Yoast premium on a couple other sites (where this problem is relevant) but not this current site. Let me know if I should be going through a premium support channel.

    Edit: to clarify what we’ve done, we’ve removed the filter function which removes the error, and we’ve changed the priority on the filter (from 11 to 100) which does not affect the error.

    • This topic was modified 2 years, 6 months ago by yikesitskevin.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Md Mazedul Islam Khan


    We can’t offer support on a custom code (needed to change (core) features of our plugin). Since we don’t want to take the risk that we break your website by suggesting an incorrect or incomplete code, we cannot advise you on how to make such changes. Maybe someone watching these forums can assist you further, but if your topic is inactive for 2 weeks, we’ll mark it as resolved to keep the overview.

    Thank you for your understanding.

    Hi @mazedulislamkhan,

    That’s alright. Thanks for getting back to me.

    Plugin Support amboutwe


    The meta box can be hidden without custom code. Is the setting not available for the custom post types in question?

    Admin > SEO > Titles & Metas* > Post Types

    Here’s an example of the screen for standard posts.
    Hide Yoast Meta Box

    * If you do not see Titles & Metas, the advanced settings can be enabled by following the steps here.

    Plugin Support amboutwe


    This thread has been marked as resolved due to lack of activity.

    You’re always welcome to open a new topic. Please read this post before open a new request.

    Thanks for understanding!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘JavaScript error being thrown when hiding Yoast CPT metabox’ is closed to new replies.