Page 1 of 2 12 LastLast
Results 1 to 10 of 17
Like Tree10Likes

Thread: Tip for adding schema to a wordpress site with Yoast

  1. #1
    James Watt's Avatar
    James Watt is offline Top Contributor
    Member Since
    Oct 2013
    Location
    Portland, OR
    Posts
    685
    Thanks
    132
    Thanked 239 Times

    Tip for adding schema to a wordpress site with Yoast

    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 Code:
    function remove_json_ld_output$data ) { 
     
    $data = array(); 

     return 
    $data


    add_filter('wpseo_json_ld_output''remove_json_ld_output'101); 
    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 by James Watt; 01-30-2017 at 02:42 PM. Reason: missing a few lines of code.

  2. Members who thanked James Watt for this post:

    Christopher W (01-31-2017),Linda Buquet (12-04-2016),Rich Owings (12-07-2016),Scott Rawlins (08-04-2016),seoWest (12-04-2016),Tim Sweeney (01-28-2017)

  3. #2
    seoWest's Avatar
    seoWest is offline Member + GMB
    Member Since
    Aug 2013
    Location
    Occidental, CA
    Posts
    78
    Thanks
    41
    Thanked 12 Times

    Re: Tip for adding schema to a wordpress site with Yoast

    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!
    James Watt likes this.
    seoWest - California SEO Company

  4. #3
    Member Since
    Sep 2012
    Location
    Nashville, TN
    Posts
    1,030
    Thanks
    127
    Thanked 148 Times

    Re: Tip for adding schema to a wordpress site with Yoast

    Is this with the premium version of Yoast?
    Tutelary Marketing, Owner
    Local Listing Ninja - Business Listing Service

  5. #4
    seoWest's Avatar
    seoWest is offline Member + GMB
    Member Since
    Aug 2013
    Location
    Occidental, CA
    Posts
    78
    Thanks
    41
    Thanked 12 Times

    Re: Tip for adding schema to a wordpress site with Yoast

    I am using the free version.
    seoWest - California SEO Company

  6. #5
    Rich Owings's Avatar
    Rich Owings is offline Member + GMB
    Member Since
    Apr 2014
    Location
    Asheville, NC
    Posts
    144
    Thanks
    74
    Thanked 17 Times

    Re: Tip for adding schema to a wordpress site with Yoast

    Thanks, James. I've started using All-in-one SEO more because they include an option to disable schema output.
    James Watt likes this.
    Rich Owings
    Local Is Where It's At | Asheville, NC SEO

  7. #6
    Member Since
    Sep 2012
    Location
    Nashville, TN
    Posts
    1,030
    Thanks
    127
    Thanked 148 Times

    Re: Tip for adding schema to a wordpress site with Yoast

    Interesting. Had no idea Yoast forces you to use their schema? It's not on any of our sites that I'm aware of?
    Tutelary Marketing, Owner
    Local Listing Ninja - Business Listing Service

  8. #7
    mborgelt's Avatar
    mborgelt is offline Top Contributor
    Member Since
    Jul 2012
    Location
    Denver, CO
    Posts
    467
    Thanks
    46
    Thanked 131 Times

    Re: Tip for adding schema to a wordpress site with Yoast

    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.
    James Watt likes this.
    Free Local Checklist
    51Blocks - "White Label" Google Places & Website Development/Hosting - Will Pay Good $$ for Wordpress website hosting referrals
    Wordpress Site Speed Problems? Site speed optimization is part of our hosting - 90's on Google PageSpeed Insights

  9. #8
    seoWest's Avatar
    seoWest is offline Member + GMB
    Member Since
    Aug 2013
    Location
    Occidental, CA
    Posts
    78
    Thanks
    41
    Thanked 12 Times

    Re: Tip for adding schema to a wordpress site with Yoast

    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
    seoWest - California SEO Company

  10. #9
    Tim Sweeney's Avatar
    Tim Sweeney is offline Member
    Member Since
    May 2015
    Location
    Binghamton, NY
    Posts
    37
    Thanks
    225
    Thanked 13 Times

    Re: Tip for adding schema to a wordpress site with Yoast

    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

  11. #10
    James Watt's Avatar
    James Watt is offline Top Contributor
    Member Since
    Oct 2013
    Location
    Portland, OR
    Posts
    685
    Thanks
    132
    Thanked 239 Times

    Re: Tip for adding schema to a wordpress site with Yoast

    @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 Code:
    function remove_json_ld_output$data ) {
     
    $data = array();

     return 
    $data;
    }

    add_filter('wpseo_json_ld_output''remove_json_ld_output'101); 
    If you'd like to use that code again without the warning this time, this is the full code block you'll need.

  12. Members who thanked James Watt for this post:

    Tim Sweeney (01-30-2017)

Page 1 of 2 12 LastLast

Similar Threads

  1. WordPress Schema.org plugins: Thoughts and recommendations?
    By djbaxter in forum Local SEO Tools & Software
    Replies: 1
    Last Post: 05-10-2014, 10:45 AM
  2. WordPress: Major update to Yoast's Local SEO plugin
    By djbaxter in forum Local SEO Tools & Software
    Replies: 0
    Last Post: 12-04-2013, 07:06 PM
  3. New Schema Creator WordPress Plugin
    By Linda Buquet in forum Local SEO Tools & Software
    Replies: 13
    Last Post: 08-02-2013, 12:04 PM
  4. New Local SEO Wordpress plugin from Yoast
    By Nick Rink in forum Local SEO Tools & Software
    Replies: 10
    Last Post: 05-30-2013, 05:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •