wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

Convert FAQ titles to headings

Open moorscode opened this issue 6 years ago • 51 comments

Currently the FAQ titles are rendered with <strong> tags. These need to be converted to headings.

Todo:

  • Convert FAQ entry title from strong to H{x} heading
  • Determine the heading level based on the highest heading block preceding the FAQ block

This issue is the quickest step to improving the rendering and results from our SEO analysis on pages which use an FAQ block. Related: https://github.com/Yoast/wordpress-seo/issues/11801

moorscode avatar Dec 12 '18 13:12 moorscode

@Dieterrr I've discussed the possible issues with @moorscode. The plan is to implement it with the automatically chosen heading levels for now. Based on this 'prototype', we'll decide if it's the way to go or if the UX needs to be finetuned.

More concrete:

  • The questions should automatically get the heading level that is 1 level lower than the heading level that is directly preceding it. So if the preceding heading is an H2, the FAQ questions should be an H3.
  • When the FAQ block is moved, the heading level should be 'recalculated'.
  • When a new heading is added above the FAQ block, the heading level should be 'recalculated'.

IreneStr avatar Jan 09 '19 10:01 IreneStr

Related: https://github.com/Yoast/wordpress-seo/pull/10891

I'm afraid in the Edit view we'll have to keep the <p> or use a <div>.

afercia avatar Jan 15 '19 09:01 afercia

Issue moved to blocked as we're going to implement inner blocks in the same release. When that happens the headers in the FAQ block will be replaced by (inner) header blocks. Issue can be picked up again as soon as inner blocks are implemented, milestone is still aimed at 9.7.

The current implementation has a small bug as it uses plain tags and it seems TinyMCE doesn't allow inline tagNames. This bug will not be fixed for now as it will be irrelevant when the innerblocks are introduced.

Dieterrr avatar Jan 15 '19 11:01 Dieterrr

Please inform the customer of conversation # 466418 when this conversation has been closed.

michaelbriantina avatar Jan 22 '19 06:01 michaelbriantina

Did this get addressed? We're on version 10.

As a workaround, we've been replacing the strong tags with our desired header tag, which works, but it breaks the Gutenberg FAQ block and makes it no longer editable.

advancedperiodontics avatar Mar 19 '19 03:03 advancedperiodontics

Hi @advancedperiodontics, no, this has not yet been addressed. Unfortunately there is is no ETA available.

Djennez avatar Mar 19 '19 08:03 Djennez

Please inform the customer of conversation # 503324 when this conversation has been closed.

mariusghitulescu avatar May 10 '19 14:05 mariusghitulescu

Using headings also makes styling easier. I'm using the same CSS for <h2> and Yoast's <strong> elements, but since it's an inline element, the margin-top and margin-bottom CSS is useless. On top of that they are not recognized by plugins that automatically generate a table of contents.

mikalehmann avatar Jul 12 '19 15:07 mikalehmann

This would indeed be very helpful. As an interim measure, is there a hook / filter that we could use to change it to a heading on the front end at least?

Jab2870 avatar Mar 31 '20 15:03 Jab2870

Please inform the customer of conversation # 614659 when this conversation has been closed.

mmikhan avatar May 24 '20 21:05 mmikhan

Is there ANY update to this? It's an incredibly frustrating issue.

KatyW333 avatar Jul 17 '20 12:07 KatyW333

Please!

gmmedia avatar Sep 06 '20 13:09 gmmedia

I've been including the following in my recent sites:

<?php
function overdide_yoast_faqs($block_content, $block){
	if ( 'yoast/faq-block' == $block['blockName'] ){
		// This turns strong tags into h2 tags
		return preg_replace('/<strong([^>]+)>(.*?)<\/strong>/','<h2\1>\2</h2>',$block_content);
	}
}
add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2 );

Hopefully soon this won't be necessary but it might help any of you in the short term.

Jab2870 avatar Sep 19 '20 14:09 Jab2870

I've been including the following in my recent sites:

<?php
function overdide_yoast_faqs($block_content, $block){
	if ( 'yoast/faq-block' == $block['blockName'] ){
		// This turns strong tags into h2 tags
		return preg_replace('/<strong([^>]+)>(.*?)<\/strong>/','<h2\1>\2</h2>',$block_content);
	}
}
add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2 );

Hopefully soon this won't be necessary but it might help any of you in the short term.

Not working for me 😱 Is this still valid? (I've introduced it in one of my functionality plugins not in the functions.php)

SirLouen avatar Feb 02 '21 20:02 SirLouen

+1 for https://wordpress.org/support/topic/yoast-not-recognizing-my-json-ld-content/

mmikhan avatar Mar 06 '21 06:03 mmikhan

Not working for me scream Is this still valid? (I've introduced it in one of my functionality plugins not in the functions.php)

@SirLouen, it's still working for me.

If you post an example of the resulting html on your website (or a link) I might be able to help

Jab2870 avatar Mar 07 '21 09:03 Jab2870

I've been including the following in my recent sites:

<?php
function overdide_yoast_faqs($block_content, $block){
	if ( 'yoast/faq-block' == $block['blockName'] ){
		// This turns strong tags into h2 tags
		return preg_replace('/<strong([^>]+)>(.*?)<\/strong>/','<h2\1>\2</h2>',$block_content);
	}
}
add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2 );

Hopefully soon this won't be necessary but it might help any of you in the short term.

Not working for me 😱 Is this still valid? (I've introduced it in one of my functionality plugins not in the functions.php)

I'm just adding that to make it working properly you need to add a return after the condition, otherwise others block are deleted 🤔 But thanks ! It's just what I was looking for 🥰

For people who are looking for the same thing with the how-to block, you just have to change the if to "yoast/how-to-block" (or put it in a OR condition) 🥳

function overdide_yoast_faqs($block_content, $block){
	if ( 'yoast/faq-block' == $block['blockName'] ){
		// This turns strong tags into h2 tags
		return preg_replace('/<strong([^>]+)>(.*?)<\/strong>/','<h2\1>\2</h2>',$block_content);
	}
        return $block_content;
}
add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2 );

ozidrice avatar Apr 16 '21 13:04 ozidrice

+1 https://www.youtube.com/watch?v=y8WwW44L1Qk&lc=Ugx1Nn86mILBVCk5yNh4AaABAg

monbauza avatar May 11 '21 11:05 monbauza

Yes please!!! It's the most basic of requirements to be able to set the Question as a heading. Is this going to be addressed since it's been asked for since 2018?

RojaBella avatar May 24 '21 13:05 RojaBella

Please inform the customer of conversation # 736838 when this conversation has been closed.

michaelbriantina avatar May 25 '21 05:05 michaelbriantina

Yes please!!! It's the most basic of requirements to be able to set the Question as a heading. Is this going to be addressed since it's been asked for since 2018?

It seems like Yoast is so big, that a simple & practical improvement has taken over two years. As someone who posted in this thread two years ago, I've since moved off of the Yoast platform.

advancedperiodontics avatar May 25 '21 16:05 advancedperiodontics

I'm looking to convert the FAQ titles to h3. I tried to add this coode:

<?php function overdide_yoast_faqs($block_content, $block){ if ( 'yoast/faq-block' == $block['blockName'] ){ // This turns strong tags into h2 tags return preg_replace('/<strong([^>]+)>(.*?)<\/strong>/','<h2\1>\2</h2>',$block_content); } } add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2 );

but it's not working for my website. It breaks the website. I can only see the header of my website without the content.

I placed the code in functions.php. Should I place it somewhere else?

Is Yoast still working on this update?

promarketer-it avatar May 26 '21 14:05 promarketer-it

I'm looking to convert the FAQ titles to h3. I tried to add this coode:

<?php function overdide_yoast_faqs($block_content, $block){ if ( 'yoast/faq-block' == $block['blockName'] ){ // This turns strong tags into h2 tags return preg_replace('/<strong([^>]+)>(.*?)<\/strong>/','<h2\1>\2</h2>',$block_content); } } add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2 );

but it's not working for my website. It breaks the website. I can only see the header of my website without the content.

I placed the code in functions.php. Should I place it somewhere else?

Is Yoast still working on this update?

you need to use this,

function overdide_yoast_faqs($block_content, $block){ if ( 'yoast/faq-block' == $block['blockName'] ){ // This turns strong tags into h2 tags return preg_replace('/<strong([^>]+)>(.*?)</strong>/','<h2\1>\2',$block_content); } return $block_content; } add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2

brodiebrodie avatar May 28 '21 09:05 brodiebrodie

I'm looking to convert the FAQ titles to h3. I tried to add this coode: <?php function overdide_yoast_faqs($block_content, $block){ if ( 'yoast/faq-block' == $block['blockName'] ){ // This turns strong tags into h2 tags return preg_replace('/<strong([^>]+)>(.*?)<\/strong>/','<h2\1>\2</h2>',$block_content); } } add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2 ); but it's not working for my website. It breaks the website. I can only see the header of my website without the content. I placed the code in functions.php. Should I place it somewhere else? Is Yoast still working on this update?

you need to use this,

function overdide_yoast_faqs($block_content, $block){ if ( 'yoast/faq-block' == $block['blockName'] ){ // This turns strong tags into h2 tags return preg_replace('/<strong([^>]+)>(.*?)/','<h2\1>\2',$block_content); } return $block_content; } add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2

Hello, thanks a lot for your reply.

I tried to place your code but it can't save the functions.php file due to this error:

syntax error, unexpected end of file, expecting ')'

Here what I see when I save: https://gyazo.com/043ae9d383ab9a6303e82e6be621fbf0

promarketer-it avatar May 28 '21 10:05 promarketer-it

hi, sorry, my mistake, last line should be

add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2 );

brodiebrodie avatar May 28 '21 10:05 brodiebrodie

hi, sorry, my mistake, last line should be

add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2 );

No problem! :)

Now it's saved now. Unfortunately the function breaks the code and the FAQ don't show up anymore: https://gyazo.com/05a369a5d55d0f6c5e3248d0ee775bb9

promarketer-it avatar May 28 '21 10:05 promarketer-it

interesting, it work for me.

Is your code exactly this;

// add h2 to yoast faq block

function overdide_yoast_faqs($block_content, $block){ if ( 'yoast/faq-block' == $block['blockName'] ){ // This turns strong tags into h2 tags return preg_replace('/<strong([^>]+)>(.*?)</strong>/','<h2\1>\2',$block_content); } return $block_content; } add_filter( 'render_block', 'overdide_yoast_faqs', 10, 2 );

brodiebrodie avatar May 28 '21 10:05 brodiebrodie

Yeah, it looks the same: https://gyazo.com/a6a2107e355920779b4a3261f4d2e0de

You can have a look here.

Strange yeah...

promarketer-it avatar May 28 '21 10:05 promarketer-it

try removing this line

// This turns strong tags into h2 tags

brodiebrodie avatar May 28 '21 10:05 brodiebrodie

Done. Still nothing...

promarketer-it avatar May 28 '21 10:05 promarketer-it