• lsmedia

    (@leadstartorg)


    It has been months and no has fixed the issue with the ProfilePage schema NOT being nested within the correct parent type, I switched to SNIP: Structured Data Plugin for WordPress

    We have no way to disable the schema by post type, here is what I was able to generate:
    add_filter( ‘wpseo_json_ld_output’, ‘disable_yoast_schema_for_specific_post_types_and_taxonomies’, 10, 1 );

    function disable_yoast_schema_for_specific_post_types_and_taxonomies( $data ) {
    // List of post types and their associated taxonomies where you want to disable Yoast schema
    $disabled_config = array(
    ‘post’ => array(
    ‘taxonomies’ => array(‘category’, ‘post_tag’, ‘post_keyword’),
    ),
    ‘page’ => array(
    ‘taxonomies’ => array(‘page_cat’),
    ),
    ‘product’ => array(
    ‘taxonomies’ => array(‘product_cat’, ‘product_keyword’),
    ),
    // Add more post types and their taxonomies as needed
    );

    // Get the current post type
    $current_post_type = get_post_type();

    // Check if we’re on a singular post/page and if the current post type is in our disabled list
    if ( is_singular() && array_key_exists($current_post_type, $disabled_config) ) {
    // Check if we need to disable based on taxonomies
    if (!empty($disabled_config[$current_post_type][‘taxonomies’])) {
    foreach ($disabled_config[$current_post_type][‘taxonomies’] as $taxonomy) {
    if (has_term(”, $taxonomy)) {
    return false; // This will disable the schema output
    }
    }
    } else {
    return false; // If no taxonomies specified, disable for the entire post type
    }
    }

    // Check if we’re on a taxonomy archive page
    if (is_tax() || is_category() || is_tag()) {
    $current_taxonomy = get_queried_object()->taxonomy;
    foreach ($disabled_config as $post_type => $config) {
    if (in_array($current_taxonomy, $config[‘taxonomies’])) {
    return false; // This will disable the schema output for this taxonomy archive
    }
    }
    }

    return $data; // Return the original data for other cases
    }

    The page I need help with: [log in to see the link]

  • You must be logged in to reply to this topic.