Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 67836

JavaScript error being thrown when hiding Yoast CPT metabox

$
0
0

Replies: 0

Hello,

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:

wp-seo-post-scraper-502.min.js:38
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 a 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.

Cheers,
Kevin.

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.


Viewing all articles
Browse latest Browse all 67836

Trending Articles