sybrew / the-seo-framework

The SEO Framework WordPress plugin.
https://theseoframework.com/
GNU General Public License v3.0
417 stars 46 forks source link

Make "no posts found" to noindex optional #194

Closed sybrew closed 3 years ago

sybrew commented 7 years ago

On some pages, like author pages, developers have designated special designs.

When archives have no posts attached, TSF adds a no-index tag. This is for semantic reasons, i.e. that's it's most likely a low-quality page.

Even though author pages are archives, they can, for example, enact as placeholders for the specific company users -- whether they have posts assigned or not.

Now, this is an "SEO security" feature. So, the off-switch (ergo optional) must be archive specific, not site specific.

An old workaround for author pages you shouldn't use (click me) ```php add_filter( 'the_seo_framework_robots_meta_array', function( $meta = array() ) { if ( is_author() ) unset( $meta['noindex'] ); return $meta; }, 10, 1 ); ```
sybrew commented 3 years ago

From TSF 4.1.4, you can overwrite the "no posts" protection.

add_filter( 'the_seo_framework_enable_noindex_no_posts', function( $noindex ) {

    // Ref: https://developer.wordpress.org/reference/functions/is_author/
    if ( is_author( [ 'author_slug', 'author_slug_2' ] ) ) {
        // Allow indexing, so set noindex to false.
        $noindex = false;
    }

    return $noindex;
} );

See https://developer.wordpress.org/reference/functions/is_author/.

N.B. Other protections and sitewide "author archive noindex"-settings may still overwrite your return value. This is intentional.