Fixing wp.template is not a function Error in Yoast SEO Plugin

Published by John on February 26, 2016 Under Wordpress

Recently, a client contacted me because they were not able to make changes to a section on their wordpress site. The section was a custom post type they use to display food menus for their local restaurant and it uses several javascript buttons to add menu sections, remove menus, modify prices, etc.

They were able to edit some parts of the page, but most of the buttons were not working.

Upon visiting the page, I observed the below error, which is related to a bug in the Yoast WordPress SEO plugin:

TypeError: wp.template is not a function
/wp-content/plugins/wordpress-seo/js/wp-seo-post-scraper-305.min.js?ver=3.0.7
e=wp.template("keyword_tab")({keyword:b,placeholder:d,score:c,hideRemove:!0,prefix:wpseoPostScraperL10n.contentTab+" ",active:!0})

In addition to showing on my clients menu custom post type page, it also shows when viewing the edit attachment page. This bug appears to be related to a bug on Github that was first reported on November 2015.

The following errors displayed when viewing an attachment page:


TypeError: document.getElementById(...) is null
/wp-content/plugins/wordpress-seo/js/dist/yoast-seo/yoast-seo-307.min.js?ver=3.0.7
document.getElementById(this.config.targets.output).appendChild(a)}

The Fix

Until Yoast updates their plugin, you can quickly fix this by removing the yoast script from select pages. The below function uses the admin_enqueue_scripts action to deregister the yoast-seo script.

Just replace ‘YOUR_POST_TYPE’ with the custom post type you are seeing the error on.

function kcr_dequeue_yoast_seo_scripts(){

$screen = get_current_screen();

if (is_object($screen) && $screen->base === ‘post’ && ($screen->post_type == ‘attachment’ || $screen->post_type == ‘YOUR_POST_TYPE’)) {
wp_deregister_script(‘yoast-seo’);
}
}

add_action(‘admin_enqueue_scripts’, ‘kcr_dequeue_yoast_seo_scripts’, 200);


No Comments |

Add a Comment