Advertisement
NubeColectiva

Como Crear Breadcrumbs en WordPress con PHP

Mar 4th, 2024 (edited)
1,509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | Source Code | 0 0
  1. // Llama la función PHP en tu código HTML
  2. <?php breadcrumb_nc(); ?>
  3.  
  4. // Función PHP
  5. function breadcrumb_nc() {
  6.     global $post;
  7.     if ( ! is_home() ) {
  8.         echo '<a href="' . site_url() . '">Home</a> &#187; ';
  9.         if ( is_category() || is_single() ) {
  10.             the_category( ' &#187; ' );
  11.             if ( is_single() ) {
  12.                 echo ' &#187; ';
  13.                 the_title();
  14.             }
  15.         } elseif ( is_page() ) {
  16.             if ( $post->post_parent ) {
  17.                 $anc   = get_post_ancestors( $post->ID );
  18.                 $title = get_the_title();
  19.                 foreach ( $anc as $ancestor ) {
  20.                     $output = '<a href="' . get_permalink( $ancestor ) . '" title="' . get_the_title( $ancestor ) . '">' . get_the_title( $ancestor ) . '</a> &#187; ';
  21.                 }
  22.                 echo $output;
  23.                 echo $title;
  24.             } else {
  25.                 echo '<strong> ' . get_the_title() . '</strong>';
  26.             }
  27.         }
  28.     }
  29. }
Tags: php breadcrumb
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement