-
-
Save amboutwe/15ad74f703f8fa3dbeb43776c4157103 to your computer and use it in GitHub Desktop.
Add "IsAccessibleForFree" to the Article schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* | |
* Add the 'isAccessibleForFree' property to Yoast's Article schema. | |
* Credit: Yoast team | |
* Last Tested: Jun 24 2025 using Yoast SEO 25.3.1 on WordPress 6.8.1 | |
* Documentation: https://developer.yoast.com/features/schema/pieces/article/#api | |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
* DIFFERENT POST TYPES | |
* Post: Change 123456 to the post ID | |
* Page: Change is_single to is_page and 123456 to the page ID | |
* Custom Post Type: Change is_single to is_singular and 123456 to the 'post_type_slug' | |
* Example: is_singular( 'cpt_slug' ) | |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
* MULTIPLE ITEMS | |
* Multiple of the same type can use an array. | |
* Example: is_single( array( 123456, 234567, 345678 ) ) | |
* Multiple of different types can repeat the if statement | |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
* @param array $data The Article schema data. | |
* @return array The modified schema data. | |
*/ | |
function add_is_accessible_for_free_to_article_schema($data ) { | |
if ( is_single(6) ) { // Change to target the Accessible identifier | |
$data['isAccessibleForFree']=true; | |
} | |
return $data; | |
} | |
add_filter('wpseo_schema_article', 'add_is_accessible_for_free_to_article_schema'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment