Sergio Pinna

Web Designer

pagine-categoria-tag

Aggiungere categorie e tag alle pagine di wordpress

Aggiungere categorie tag alle pagine WordPress può risultare utile quando si necessita di categorizzare le pagine, per esempio.

WordPress è sicuramente un eccellente CMS, ma è nato per la creazione e la gestione di blog. Dunque esprime per default la sua forza nella gestione degli articoli.Infatti gli articoli in WordPress hanno per default la capacità di essere impostati in categorie e tag.

E per le pagine? Direte voi, per le pagine solitamente non ci sono grossi problemi, ma se proprio hai necessità di usare categorie e tag anche per le pagine è possibile aggiungere categorie e tag anche alle pagine mediante questa semplice funzione:

function add_taxonomies_to_pages() {
	register_taxonomy_for_object_type( 'post_tag', 'page' );
	register_taxonomy_for_object_type( 'category', 'page' );
}
add_action( 'init', 'add_taxonomies_to_pages' );
if ( ! is_admin() ) {
	add_action( 'pre_get_posts', 'category_and_tag_archives' );
}
function category_and_tag_archives( $wp_query ) {
	$my_post_array = array('post','page');
	if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) ) {
		$wp_query->set( 'post_type', $my_post_array );
	}
	if ( $wp_query->get( 'tag' ) ) {
		$wp_query->set( 'post_type', $my_post_array );
	}	
}

Se ti è piaciuto, Aggiungere categorie tag alle pagine wordpress, allora ti potrà interessare Usare le categorie, the_category(), senza link

Fonti:
How to Add Categories and Tags to Pages in WordPress

Condividi questo articolo