Skip to main content




Hoy estaba trabajando en un nuevo tema Premium de WordPress y una de las cosas que incluía era la navegación de ruta de navegación personalizada. Para que se vea mejor, debe tener una estructura como esta: inicio> categoría> título de la publicación. A continuación se muestra el código que utilicé para obtener la categoría actual de cualquier publicación y vincularla.

To show link de categoría con código personalizado

Just paste this code where you want your category link to appear. This will display a link to the first category of your post. This code can be placed in any theme template file, even outside of the loop, but it will not work when placed in functions.php unless it is "hooked" on an action hook that runs after WordPress has initialized like "init".

<?php
$get_cat        = get_the_category();
$first_cat      = $get_cat[0];
$category_name  = $first_cat->cat_name;
$category_link  = get_category_link( $first_cat->cat_ID ); ?>
<a href="<?php echo esc_url( $category_link ); ?>" title="<?php echo esc_attr( $category_name ); ?>"><?php echo esc_html( $category_name ); ?></a>

Enlace de categoría para taxonomía personalized

Si desea mostrar el enlace de la primera categoría para la taxonomía personalizada, el código es un poco diferente. A modo de ejemplo, si está utilizando un tema premium como nuestro «Tema total de WordPress”Entonces notará que hay tipos de publicaciones personalizadas como Briefcase, Personal y testimonios y algunos de estos tienen taxonomías personalizadas como“ Categoría de Portafolio ”. Entonces, si quisiera mostrar la primera categoría en la que se encuentra una publicación de cartera, entonces haría algo como esto:

<?php
$get_cat        = wp_get_post_terms( get_the_ID(), 'portfolio_category' );
$first_cat      = $get_cat[0];
$category_name  = $first_cat->cat_name;
$category_link  = get_category_link( $first_cat->cat_ID ); ?>
<a href="/en/</?php echo esc_url( $category_link ); ?>" title="<?php echo esc_attr( $category_name ); ?>"><?php echo esc_html( $category_name ); ?></a>

Notice how in this example we use wp_get_post_terms () instead of get_the_category ()? This is because get_the_category () will only work for the main category taxonomy in WordPress, not for any custom taxonomy.

Cómo mostrar el enlace de categoría con Yoast SEO Breadcrumbs

yoastseo-8338899

Your other option is to simply use the breadcrumb features built into the Yoast SEO Plugin. Usually, when the current category of a post is displayed, it is a good idea to show it in your breadcrumb because it provides easy navigation through your site for users, but at the same time it can help in your efforts to SEO. Many free and premium WordPress themes actually use and recommend Yoast SEO for adding breadcrumbs because it is easy and effective.

Para utilizar la función de migas de pan de Yoast SEO, primero deberá asegurarse de que su tema de WordPress be compatible. Si no es así, es fácil de solucionar. Simplemente pegue el siguiente código en su archivo de tema donde desea mostrar sus rutas de navegación (de forma general single.php o page.php encima del título de la página):

<?php
if ( function_exists('yoast_breadcrumb') ) {
     yoast_breadcrumb('<p id="breadcrumbs">','</p>');
}
?>

Once your theme is ready, you can log into WordPress and go to SEO> Advanced> Breadcrumbs.

set-yoast-breadcrumbs-3903794

Now you can add your custom breadcrumb settings. Click save and your breadcrumbs will show up as you set them up.