Answered: edit answer to accepted answer in schema

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

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:
Warren Buffett's public Kraft Heinz criticism is extremely unusual for the typically passive owner
Gold is on a record run — here's how to invest, according to experts
Undersea cables cut in the Red Sea, disrupting internet access in Asia and the Mideast
South Korea says it has reached a deal with the U.S. for the release of workers in a Georgia plant
Nvidia's breakdown, dismal jobs report and other ills fail to slow down this bull market by much yet
Powerball lottery players in Missouri and Texas to split estimated $1.8 billion jackpot
DOJ says names of two associates Epstein wired $100k and $250k to should stay secret
Japan Prime Minister Ishiba Shigeru says he will step down after election setback
Jim Cramer says this stock has the 'most upside' in our portfolio ahead of rate cuts
Shares of this under-the-radar weight-loss drug play could double, says Leerink Partners