Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

295
Vistas
How to Echo only the text with "h5" tags

I'm trying to echo text with special tags "h5" So I added this code inside function.php to echo the short description under each product

add_action( 'woocommerce_after_shop_loop_item', 'woo_show_excerpt_shop_page', 5 );
function woo_show_excerpt_shop_page() {
    global $product;
    echo $product->post->post_excerpt;
}

It works but it echo all the text

So I edited the code to only pick up h5 tags

  add_action( 'woocommerce_after_shop_loop_item', 'woo_show_excerpt_shop_page', 5 );
    function woo_show_excerpt_shop_page() {
        global $product;
//pick up only h5
$html = '<h5></h5>';
$dom = new DOMDocument();
$dom->loadHTML( $html );
echo $dom->getElementsByTagName("h5")->item(0)->textContent;
    }

Now my problem is the text doesn't show up at all! What I'm doing wrong?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Remember that computers are stupid, they don't know what you mean, only what you say. So in this code:

$html = '<h5></h5>';
$dom = new DOMDocument();
$dom->loadHTML( $html );
echo $dom->getElementsByTagName("h5")->item(0)->textContent;

The computer will load the string '<h5></h5>', parse it as HTML, and then extract h5 elements from it. At no point will it look at any other text.

What you want to do is look for h5 elements inside another string, so you need to tell the computer what other string. Based on your first attempt, the string you want to look in is $product->post->post_excerpt, so that is the value you need in $html:

global $product;
$html = $product->post->post_excerpt;
$dom = new DOMDocument();
$dom->loadHTML( $html );
echo $dom->getElementsByTagName("h5")->item(0)->textContent;
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda