• Resolved poksi

    (@poksi)


    Hello,

    I’m using a third party plugin to create set of posts in WordPress that doesn’t utilize custom post types.

    I want to exclude all child post (/abc/xyz/) titles and metas NOT to be rewritten by The SEO Framework except for the parent page (/abc/).

    I found this code snippet somewhere that excludes child posts correctly but also for the parent page (/abc/).

    As I’m not much of an coder can someone help me to modify this code so that ONLY child posts of /abc/ would be excluded?

    add_action( 'after_setup_theme', function() {
      $exclusions = array(
        '/abc/',
      );
      $tsf = function_exists( 'the_seo_framework' ) ? the_seo_framework() ?: null : null;
      if ( ! isset( $tsf, $_SERVER['REQUEST_URI'] ) ) return;
      foreach ( $exclusions as $exclusion ) {
        if ( 0 === strpos( $_SERVER['REQUEST_URI'], $exclusion ) ) {
          remove_action( 'init', array( $tsf, 'init_the_seo_framework' ), 0 );
        break;
        }
      }
    } );
Viewing 1 replies (of 1 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    That snippet is from a gist I created 3 years ago. The API is now more versatile, and easier to use.

    In any case, you’d want to use a regular expression. The most accessible function for this is preg_match().

    The snippet below should do (untested!).

    add_filter( 'the_seo_framework_query_supports_seo', function( $supported ) {
    
    	if ( preg_match( '/^\/abc\/.+/i', parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) ) ) {
    		$supported = false;
    	}
    
    	return $supported;
    } );

    The .+ part is a wildcard that requires at least something appended to the base URL of /abc/. We have to parse the URL because otherwise any anchor (#someheader) or query (?some=query) attached to the URL would also exclude support for the base path of /abc/.

    I hope this helps!

Viewing 1 replies (of 1 total)

The topic ‘Exclude by URL’ is closed to new replies.