Joined
Oct 25, 2013
Messages
752
Reaction score
286
By tip, I mean removing the JSON-LD schema in Yoast so that when you add yours, you don't have two. I'm convinced that Google doesn't get confused when they see two markups (many sites have it) but still, it's easy to disable Yoast's schema, so you might as well.

Yoast has no UI button to get rid of schema, but they do have a hook in the API you can call. Go to the functions.php file in your theme, and add this line of code before the ?> at the end of the file.

EDIT: I previously had only part of the code needed, this is the updated, full code.

PHP:
function remove_json_ld_output( $data ) { 
 $data = array(); 

 return $data; 
} 

add_filter('wpseo_json_ld_output', 'remove_json_ld_output', 10, 1);

As always, if you aren't sure what you're doing, make sure you save a backup. Hosing one of the core theme files is never a good thing, and you can easily break your whole site temporarily just by having a ; in the wrong place.

To test it, refresh a page on your site, view source and do a ctr+f looking for "json", and you shouldn't see the Yoast schema anymore.

Fixing it this way will last even if you update the Yoast plugin, so do this instead of changing code in the actual plugin file.

Is this already common knowledge? Do you bother removing Yoast's schema when you add proper schema for a client? Did this work for you? Hope it helped!
 
Last edited:

seoWest

Member
Joined
Aug 15, 2013
Messages
63
Reaction score
12
Hey James,

Nope. Not common knowledge to me anyway. I began wondering about how to remove Yoast's schema, while adding my own schema mashup via Tag Manager and then validating. I noticed two sets of schema, with mine being the more accurate of the two ;-)

Anyway, your filter worked great, thank you!
 

JoshuaMackens

Local Search Expert
Joined
Sep 12, 2012
Messages
1,950
Reaction score
579
Interesting. Had no idea Yoast forces you to use their schema? It's not on any of our sites that I'm aware of?
 

mborgelt

Member
Joined
Jul 22, 2012
Messages
479
Reaction score
155
Thanks for sharing this, James. We add our JSON plugin to all of our client's sites and we use Yoast religiously but I have never seen Yoast's schema when we check the structured data. I will definitely keep an eye out from now on since you brought it up.
 

seoWest

Member
Joined
Aug 15, 2013
Messages
63
Reaction score
12
Hey James,

A few days ago when I first added the code, things were working great, however, I just checked-back on the site, and now I am getting the following Warning in the browser:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'remove_json_ld_output' not found or invalid function name in /wp-includes/plugin.php

Any idea how to resolve this?

Thanks!

Dino
 

Tim Sweeney

Member
Joined
May 21, 2015
Messages
41
Reaction score
11
James - Thanks for the useful tip. I tried this on a staging site and it removed the Yoast Schema successfully. While I use Wordpress, I usually avoid making modifications to the function.php file.

My main question is, if there is an update to Wordpress and/or the theme in use, how likely would it be that this modification to the function file would cause an issue?

Thanks
 
Joined
Oct 25, 2013
Messages
752
Reaction score
286
@Tim Sweeny - yeah, you need a little knowledge of what's going on under the hood before the function file can feel safe to use, but for a lot of features and changes there's no way around it. Even something as basic as setting up a child theme requires editing the function.php file. For this change specifically, there's basically two things that are going on.

First, wordpress has something called 'hooks'. It lets developers create ways for you to change their plugin/theme functionality, without having to change the core files themselves. They create a hook that gets called right before a certain action, and let you feed in functions you want to be executed before that action is run. You can use hooks to edit the email before Contact Form 7 sends it out, or in this case, Yoast has a hook for the JSON-LD output, giving you a chance to change, extend, or in our case, remove the code before it gets put on your site.

Wordpress will never get rid of hooks, the add_filter function will always be there. Even if they go in a different direction for future versions of wordpress, they'll still keep add_filter as a deprecated function. It's used extensively all over the place, probably in almost every single plugin you've ever used. If add_filter is ever removed as a function you can call, it'd break an enormous number of plugins and themes.

Having action hooks and filters isn't unique to wordpress either, I have a background in more traditional software engineering, and it's a programming concept that's been used for decades in all kinds of applications, from Drupal (a CMS competitor to wordpress) to videogame physics APIs. It's basically used anywhere that a developer wants to let you extend their code, without actually giving you access to the code you're altering.

So if the add_filter function is always going to be there, there's only one other thing that could change in a future update. Yoast could stop using the wpseo_json_ld_output hook. If you try and add_filter on a hook that hasn't been defined though, nothing happens. There's no error or anything, your code just doesn't change anything if there's no filter defined to add your function to.

Hopefully all that made some kind of sense. The tl;dr version though, if this code breaks in the future, all it will do is stop removing yoast's JSON code, it won't actually break anything.

@seoWest:

Looking at my top post, it looks like I somehow only added part of the code you need, I can't believe I did that. Sorry for the misunderstanding. Basically the line I had in my original post registers the function you want to be called with Yoast's JSON hook, but you still have to define that new function. Here's the full code I meant to paste in originally:

PHP:
function remove_json_ld_output( $data ) {
 $data = array();

 return $data;
}

add_filter('wpseo_json_ld_output', 'remove_json_ld_output', 10, 1);

If you'd like to use that code again without the warning this time, this is the full code block you'll need.
 

Tim Sweeney

Member
Joined
May 21, 2015
Messages
41
Reaction score
11
James - Thanks! Since I'm more of a marketer than designer/programmer I try to tread lightly when it comes to modifying something such as the functions file. Making backups, trying it on a staging site has so far saved me from a major issues. Thanks again.
 

djbaxter

Administrator
Administrator
Moderator
Joined
Jun 28, 2012
Messages
3,512
Reaction score
1,659
To answer your other question, Tim, any edits to core Wordpress files will indeed be overwritten the next time Wordpress updates.

There are, however, some Wordpress plugins that allow you to insert scripts into the < head > section of your Wordpress plugins.

That way, your additions would not be overwritten when Wordpress updates.

This may be a way to do this without having to edit core files? (I haven't tried this.)

See https://wordpress.org/plugins/search.php?type=term&q=head+section
 
Joined
Oct 25, 2013
Messages
752
Reaction score
286
@Tim, yeah, I know more than the average bear maybe, but I'm no seasoned developer. Sometimes I know just enough to get myself into trouble... and even the most seasoned developers should all still use staging sites and testing. My background's in videogame programming originally, and I could tell you some stories about just how important testing is in a big team environment. I know a guy back in college working at a game company that had several days where no one could do work, always because someone committed some broken code at 1am the night before and hosed everything. The next day you'd have everyone sitting around, while one guy was furiously trying to fix what he'd accidentally broken. Testing, no matter your skill, is always important, especially on live client sites.

As far as editing the core wordpress files, and changing the <head> and such... yeah, never edit any wordpress core files. You should never edit any plugin files either, or any theme that you think might be updated someday. Child themes are there in fact so that you can make changes without risking them getting overwritten next time the theme updates. As for adding stuff to the head section, usually I'm working in a custom theme, and you just change things in the header php file, but if you don't have that set up, a plugin might be the way to go.
 
Last edited:

Eric Rohrback

Moderator
Joined
Oct 3, 2012
Messages
1,021
Reaction score
343
Hey James,

A few days ago when I first added the code, things were working great, however, I just checked-back on the site, and now I am getting the following Warning in the browser:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'remove_json_ld_output' not found or invalid function name in /wp-includes/plugin.php

Any idea how to resolve this?

Thanks!

Dino

Check for extra spaces or missing brackets/missing elements. Simple errors like that in the php files will crash the site.

Always use a child theme to make custom changes like this to a site, otherwise everything you do will be overwritten (as others have pointed out).
 
Joined
Oct 25, 2013
Messages
752
Reaction score
286
Check for extra spaces or missing brackets/missing elements. Simple errors like that in the php files will crash the site.

Always use a child theme to make custom changes like this to a site, otherwise everything you do will be overwritten (as others have pointed out).

missing semi colons and such can definitely cause problems. In this case though, it's just because the remove_json_ld_output function wasn't defined. I updated my code snippet, it should work fine now.
 
Similar threads
Thread starter Title Forum Replies Date
S Best Tips for Organic Traffic Organic SEO 3
F Do You hate Writing Content? Here Are Some Tips to Ease the Pain. Recycle Bin 0
BWrightTLM Yelp Business Listing Tips Local Reviews 4
Justin Mosebach TripAdvisor Optimization Tips? Local Search 8
djbaxter Google: Tips for responding to reviews Google My Business & Google Maps 0
R Free Webinar: Organic Facebook Marketing Tips for Local Businesses Events 0
PaulSteinbrueck Contribute a tip about online reviews? Contact Us Messages 0
Colan Nielsen Image Thumbnails on Mobile: How To Get Them (Awesome Tips) Local Search 2
Garrett Sussman Wedding Industry Review Management Tips & Insights Local Reviews 0
Garrett Sussman Realty Industry Review Management Tips & Insights Local Reviews 0
Garrett Sussman Healthcare Industry Review Management Tips & Insights Local Reviews 2
Garrett Sussman Hospitality Industry Review Management Tips and Insights Local Reviews 0
Garrett Sussman Legal Industry Review Management Tips & Insights Local Reviews 0
Garrett Sussman Home Services Industry Review Management Tips & Insights Local Reviews 2
T Client Getting Review Spammed Like Crazy - Any Additional Tips? Local Reviews 11
Eric Shanfelt VIDEO TIP: How to Make a Direct Google Reviews Link Local Reviews 4
Garrett Sussman 7 Simple Tips to Inflate Your Marketing Agency's Perceived Size Local Reviews 0
J Some Local SEO tips for ranking in London? Local Search 0
S Tips Wanted To Improve My YouTube Subs Local Search 0
H Google Images associated with GMB. Getting worse? Any new tips Google My Business & Google Maps 3
H Tips for avoiding the Hall of Shame and the wrath of the SEO Police? Spam on Google 3
Garrett Sussman 5 Tips to Strengthen Your Reputation Management Strategy and Boost Your SEO Local Reviews 0
JoyHawkins 201 Actionable SEO Tips Organic SEO 1
James Watt Google's new mobile testing tool, plus some mobile optimization tips Local Search 1
Garrett Sussman Hug Your (Online Review) Haters: Tips From Jay Baer's Best Selling Book Local Reviews 4
JoyHawkins 34 Experts Share Their #1 Actionable Local SEO Tip Local Search 4
Linda Buquet Experts Share Tips: How to Optimize your Google My Business Listing Google My Business & Google Maps 1
timcapper Citation Tips for Dubai and UAE Citations 0
Linda Buquet 73 SEO Experts Share Penguin Penalty Removal Tips Organic SEO 3
L Critical Google Local Dupe Research Tips: New Tool & New Trick Google Duplicates & Merges 9
Linda Buquet Critical Google Local Dupe Research Tips: New Tool & New Trick Google Duplicates & Merges 9
Colan Nielsen Local Finder Photo Optimization Tips Google My Business & Google Maps 14
D Do You hate Writing Content? Here Are Some Tips to Ease the Pain. Local Content 5
Dustybones Do You hate Writing Content? Here Are Some Tips to Ease the Pain. Local Content 5
L 3 Tips for Developing Locally Focused Blog Content - From a Local Content Writer Local Content 3
Linda Buquet 3 Tips for Developing Locally Focused Blog Content - From a Local Content Writer Local Content 3
Linda Buquet 90 SEO Experts Share their Best White Hat Link Building Tips - Ahrefs Blog Organic SEO 2
Dustybones Got A bad Review? Here Are Some Tips on How to Deal With It Local Reviews 3
Dustybones 5 Great Tips to Improving Your Schema Markup Local Search 1
L Getting Content from Local Clients is Like PULLING TEETH! Part 2 - More Tips Local Content 2
Linda Buquet Getting Content from Local Clients is Like PULLING TEETH! Part 2 - More Tips Local Content 2
Linda Buquet 17 Tips to Help You Measure Local Search ROI & Keep Your Clients! Joy Hawkins Consultant's Corner 4
Colan Nielsen Great Keyword Research Tip Local Search 6
Linda Buquet Local Video SEO Making You Craz-EO? Here are some tips Marketing 0
CaseyMeraz Competitive Analysis Tips for Local SEO Local Search 2
L Getting Content from Local Clients is Like PULLING TEETH! Tips, Tricks & Tools Local Content 0
Linda Buquet Getting Content from Local Clients is Like PULLING TEETH! Tips, Tricks & Tools Local Content 0
Dustybones URL Structure Tips From Gary Illyes Local Search 6
Linda Buquet 10 Content & Copywriting Tips for Dentists that Put you Ahead of the Pack Local Search 0
CaseyMeraz 20 Local SEO Nerds Share Strategy Tips Local Search 1

Similar threads

Login / Register

Already a member?   LOG IN
Not a member yet?   REGISTER

Most UpVoted Answers

LocalU Podcasts

  Promoted Posts

New advertising option: A review of your product or service posted by a Sterling Sky employee. This will also be shared on the Sterling Sky & LSF Twitter accounts, our Facebook group, LinkedIn, and both newsletters. More...
Google Product Exert


Top Bottom