Riley left court saying nothing, with his grey tracksuit top pulled over his head.

During the 10-minute hearing his solicitor Michael Walsh said: "He is mortified by his own behaviour and he apologises for any upset that may have been caused to everybody."

Mr Walsh asked the magistrates to free his client on bail, telling them the only reason he had been held overnight was for his own safety.

He suggested that Riley may be in more danger in a Leeds prison than he would be walking the streets.

Earlier, Sandra White, prosecuting, told the court that Riley had posted a number of offensive tweets, only some of which related to the murder of Mrs Maguire.

Promoted stories

She said the offence had come to the attention of West Yorkshire Police because of this connection but told the bench that it should properly have been charged in South Wales.

Ms White said the magistrates in Swansea would also be in a position to deal with Riley's existing community order. No details of this order were given in court today.

Riley was given bail on condition that he does not use social networking sites and the internet generally between now and his appearance on Thursday.

The defendant sat in the dock with a woman security officer, wearing his track suit top over a grey T-shirt and blue jogging bottoms.

Riley is the second person to be charged with sending a "malicious communication" in the wake of the death of Mrs Maguire who was stabbed to death in her classroom.

Jake Newsome, 21, from the Harehills area of Leeds, was released on bail after being charged for the alleged abuse, officers said.

He is due to appear before Leeds Magistrates' Court on Wednesday May 14.

Mrs Maguire died after she was attacked during a Spanish lesson at the school where she had taught for more than 40 years.

She was due to retire in September.

The killing is thought to be the first time a teacher has been stabbed to death in a British classroom and the first murder of a teacher in a school since the 1996 Dunblane massacre.

Yesterday, prayers were said for Mrs Maguire and her family.

Deacon Sean Quigley included the family of the 15-year-old boy charged with murdering the 61-year-old in his homily at Corpus Christi Church in Leeds which is attached to the school.

Mr Quigley, a retired teacher at the college who knows the Maguire family, told the congregation: "The school, staff and pupils have been consoled by messages from around the world and by many gifts of flowers, and also of food and books.

"The family of the young man involved also have been consoled in their great distress by the messages of love they have received."

A 100m-long shrine of floral tributes now connects the church with the school gates.

A book of condolence has also been opened at the cathedral in Leeds for those who want to express their sympathies.

Share article

Later today, past and present pupils from Corpus Christi are expected to gather on the field opposite the school to remember Mrs Maguire and mark a week since her death.

:: A 15-year-old boy appeared in court last week charged with mother-of-two Mrs Maguire's murder and was remanded in custody.

Ipsoregulated

This website and associated newspapers adhere to the Independent Press Standardards Organisations's Editors' Code of Practice. If you have a compaint about editorial content which relates to inaccuracy or intrusion, then please contact the editor here. If you are dissatisfied with the response provided you can contact IPSO here