Answered: edit answer to accepted answer in schema

Post date: 2021-07-22 06:38:28
Views: 252

How can I modify schema so that the answer directly becomes the best and chosen answer without choosing it

So you want the schema to return the answer as if it was chosen, even if it wasn't. This is an odd request, but here it goes :)

1. Edit your qa-theme/<your-theme>/qa-theme.php file

2. Add or merge this function:

public function initialize() {
    parent::initialize();
    if ($this->template === 'question' && !empty($this->content'a_list']'as'])) {
        $this->content'a_list']'as']0]'tags'] = str_replace('itemprop="suggestedAnswer"', 'itemprop="suggestedAnswer acceptedAnswer"', $this->content'a_list']'as']0]'tags']);
    }
}

Note I'm just turning into accepted the first answer only, as a failsafe.

Please click Here to read the full story.
 
Other Top and Latest Questions:
HPE CEO Neri pleased with quarter despite AI revenue delays as stock bounces from post-earnings dip
'Foolproof' nail kits and 'Holy Grail' gloves: 11 gifts for $50 or less, recommended by CNBC staff
Costco adds Biden Commerce Sec. Gina Raimondo to board on heels of Trump tariff lawsuit
Social Security changes on the table as House bills advance: New retirement age terms, more ID theft services
India's largest airline melts down after new crew rest rules
$208 million wiped out: Yieldstreet investors rack up more losses as firm rebrands to Willow Wealth
London's answer to Wall Street gains momentum as major firms sign on
'Trump accounts' could give your child up to $1,000 for free. Your top questions, answered
CNBC Sport: U.S. men’s soccer is sick of losing the World Cup — and now it has a plan
Netflix's plan to buy Warner Bros. throws the theater industry into upheaval