How to disable global Organization/LocalBusiness schema on archive pages?

Hello,

I am using the ClassicSEO plugin and need some help with the schema output.

The Problem:
The plugin correctly outputs Organization and LocalBusiness schema, but it does so on every page of my website, including tag and category archives. According to Google’s Rich Results Test, this schema appears on my tag archive pages.

My Goal:
I want to disable this global Organization/LocalBusiness schema on all archive pages (tags, categories, etc.) so that my own custom function can output a more appropriate CollectionPage schema on these pages. I only want the Organization/LocalBusiness schema to appear on my homepage or contact page.

What I have tried so far (without success):

  1. Plugin Settings: I have set the “Contact Page” and “About Page” in the “Local SEO” settings, but this did not stop the schema from appearing on archive pages.
  2. remove_action in functions.php: I used Query Monitor and found the function Classic_SEO\Frontend\Add_Attributes->add_attributes() running on the wp_head hook with priority 99. My attempts to remove it with a custom function have failed.
  3. Output Buffering: I even tried to remove the script from the final HTML output using ob_start() and preg_replace(), but this also failed to remove the plugin’s schema.

My Question:
Is there a specific setting I am missing, or what is the correct PHP filter or action I should use in my functions.php to prevent the Organization and LocalBusiness schema from being output on archive pages?

Thank you for your help!

This is probably one for @Simone

I’m not so sure this will solve your problem, but this snippet (I’ve tested using a mu-plugin) removes Classic_SEO\Frontend\Add_Attributes->add_attributes().

add_action( 'wp', function () {
	if( ! is_archive() ) {
		return;
	}
	global $wp_filter;
	foreach( $wp_filter[ 'wp_head' ][ '99' ] as $key => $value ) {
		if ( ! str_ends_with( $key, 'add_attributes' ) ) {
			continue;
		}
		if ( get_class( $value[ 'function' ][0] ) !== 'Classic_SEO\Frontend\Add_Attributes' ) {
			continue;
		}
		remove_action( 'wp_head', $key, 99 );
	}
});

Note: edited to hook later and check if the page in an archive page.

2 Likes

Thanks, I will report later

Hello everyone,

I’m currently working on implementing customized Schema.org markup (JSON-LD) for my website via functions.php. I’m encountering a very strange problem and hope someone here has a brilliant idea.

The goal:
A function should write a different, appropriate schema to the wp_head depending on the page type (is_single, is_front_page, is_archive, etc.).

The problem:
The function executes correctly and outputs the schema, but only for single posts (is_single()). On all other page types (home page, static pages, archives), the function’s output does not appear in the source code, even though the function itself is demonstrably executed.

What we’ve already done (the debugging journey):

Canary test: A simple test (echo “”) has proven that functions.php is working correctly and we can insert code into the wp_head.

Hook timing: We changed the hook from add_action(‘wp_head’, …) to add_action(‘template_redirect’, function() { add_action(‘wp_head’, …); }); to ensure that all WordPress conditions (is_front_page, etc.) are reliable.

Conditions verified: We built a debug function (“interrogator”) directly into the function that outputs the status of all conditional tags (is_single(), is_archive(), etc.) at the top of the page. The result was clear: The conditions return the correct TRUE/FALSE values. The if/elseif logic is therefore executed correctly.

Conflict analysis: The cause was a conflict with an old SEO plugin (“Classic SEO”). After deactivating it, the schema output now works on most pages. (You could then describe the final test results here.)

Blockquote

/**

  • Hakt die Schema-Erzeugung zum korrekten Zeitpunkt ein.
    */
    add_action( ‘template_redirect’, ‘schema_erzeugung_sicher_starten’ );
    function schema_erzeugung_sicher_starten() {
    add_action( ‘wp_head’, ‘meine_schema_markup_erzeugen’ );
    }

/**

  • Erzeugt das kontext-abhängige Schema-Markup.
    */
    function meine_schema_markup_erzeugen() {
    // … (Hier den Inhalt der Funktion aus Version 8 einfügen)
    }

Blockquote

My question to the community:
Even though we’ve solved the problem by deactivating the plugin, I’m still interested in the technical cause. Does anyone have any idea what mechanism a plugin can use to suppress the output of another, correctly hooked function in the wp_head, but only on certain page types? Are there any known, aggressive filters or obscure buffering techniques that could cause this?

Thank you for your insights!

how about using wp_reset_query() ?
just paste it before your code

wp_reset_query();