• Resolved Nikodemsky

    (@nikodemsky)


    So is there a way to add custom taxonomies to Seo Framework? I would like to apply noindex/noarchive to custom taxonomy of mine, but it’s not listed in plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi @nikodemsky,

    To allow the metabox to be displayed for custom taxonomies, the custom taxonomy has to be marked public and show a user interface.

    Please see this method: add_taxonomy_seo_box_init().

    Alternatively, you can force this by adding the action to the taxonomy regardless.

    i.e.

    function_exists( 'the_seo_framework' ) and add_action( 'my_tax_name_edit_form', array( the_seo_framework(), 'pre_seo_box' ), 0, 2 );
    

    I hope this helps! If you require more information, feel free to ask! Cheers ??

    Thread Starter Nikodemsky

    (@nikodemsky)

    Hey, could you give me an example with actual custom taxonomy(or rather custom post type).

    Let’s say, that my custom post type name is “mycoolposts”, how would code look like for that to implement?

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi @nikodemsky,

    Then it would be:

    
    function_exists( 'the_seo_framework' ) and add_action( 'mycoolposts_edit_form', array( the_seo_framework(), 'pre_seo_box' ), 0, 2 );
    

    More elegantly:

    
    $my_tax_names = array( 'mycoolposts', 'movies', 'snippets' );
    
    if ( function_exists( 'the_seo_framework' ) ) {
    	$tsf = the_seo_framework();
    	foreach ( $my_tax_names as $tax_name ) {
    		add_action( $tax_name . '_edit_form', array( $tsf, 'pre_seo_box' ), 0, 2 );
    	}
    }

    Cheers!

    Thread Starter Nikodemsky

    (@nikodemsky)

    Tried that and it’s not showing on settings page:

    View post on imgur.com

    Here’s custom post/taxonomy code from functions:

    //custom post type
    add_action( 'init', 'trackcamp_gallery_post_type' );
    function trackcamp_gallery_post_type() {
    	register_post_type( 'gallery_post',
    		array(
    			'labels' => array(
    				'name' => __( 'Gallery' ),
    				'singular_name' => __( 'Gallery' ),
    				'supports' => array( 'title', 'editor', 'thumbnail' ),
    				'taxonomy' => 'series'
    			),
    		'public' => true,
    		'has_archive' => true,
    		)
    	);
    }
    add_theme_support( 'post-thumbnails', array( 'post', 'gallery_post' ) );
    //custom taxonomy
    	function trackcamp_gallery_taxonomy_init() {
       register_taxonomy(
        'filter',
        'gallery_post',
        array(
            'hierarchical' => true,
            'label' => 'Filter',
            'query_var' => true,
            'rewrite' => array('slug' => 'filter')
        )
    );
    }
     
    add_action( 'init', 'trackcamp_gallery_taxonomy_init' );

    and code i’ve used to register it for plugin:

    $my_tax_names = array( 'Gallery', 'gallery_post', 'snippets' );
    
    if ( function_exists( 'the_seo_framework' ) ) {
    	$tsf = the_seo_framework();
    	foreach ( $my_tax_names as $tax_name ) {
    		add_action( $tax_name . '_edit_form', array( $tsf, 'pre_seo_box' ), 0, 2 );
    	}
    }

    Have i missed something ?

    Plugin Author Sybre Waaijer

    (@cybr)

    Aha! Now I fully understand your question ?? I’m sorry for the misunderstanding.

    What the code I supplied did was adding a new metabox to the taxonomy edit pages. They didn’t do anything for the global SEO options.

    You’d need to filter the_seo_framework_robots_settings_tabs, but that’s a bit too advanced and actually the wrong place to do so (because of the nested arrays). Currently, there’s no right way to add such options.

    There’s a related GitHub issue comment on this:
    https://github.com/sybrew/the-seo-framework/issues/20#issuecomment-252874509

    There’s a right way to do this, however…
    …it provides no user interface.

    Please see filter the_seo_framework_robots_meta_array: (untested!)

    add_filter( 'the_seo_framework_robots_meta_array', 'my_robots_adjustments', 10, 1 );
    function my_robots_adjustments( $robots = array() ) {
    
    	// Pick one or leave both conditions:
    	if ( 'mycoolposts' === get_post_type() || is_post_type_archive( 'mycoolposts' ) ) {
    		// Keys match the value. Legacy code.
    		$robots['noindex'] = 'noindex';
    		$robots['nofollow'] = 'nofollow';
    	}
    
    	return $robots;
    }

    I hope this helps! Cheers ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Indexing for custom taxonomies?’ is closed to new replies.