If Willie Randolph appears at the All-Star Game it won’t be as a coach in the National League dugout.

Randolph was replaced today by Cubs manager Lou Piniella on the National League coaching staff, The Post has learned.

Major League Baseball is working with Randolph to see if he still wants to be involved in the game at Yankee Stadium on July 15 in some capacity. It is unclear what role he could take, but MLB is hopeful of figuring some way to keep Randolph involved in the event if that is what he wants.

Randolph was named to the NL staff by Rockies manager Clint Hurdle earlier this season. The move made sense with Randolph managing the Mets and with his history as a Yankee.

When the Mets fired Randolph last week, things became awkward. The winner of the All-Star Game gets home-field advantage for its league in the World Series. MLB did not want a situation where a coach with no affiliation to a team had a role in the game.

MLB is talking to Randolph about scenarios that would keep him involved in the event. He could play a role in the pregame events that day, such as pitching batting practice.

“It’s an unprecedented situation,” said Katy Feeney, a senior vice president of MLB. “We’re still trying to figure out what works best for everybody. A lot if it depends on what (Willie) wants to do.”

Randolph had to skip the 2007 All-Star Game because of right shoulder surgery after being named a coach. He was the starting second baseman in the 1977 All-Star Game, the prior one held at Yankee Stadium.

Piniella played for the Yankees from 1974-84, winning World Series championships in 1977 and 1978. He managed the Yankees in 1986 and 1987, then served a second stint as manager during the second half of the 1988 season.

“Listen, I”m happy that they asked,” Piniella said. “I accept. I look forward to going to New York. This will be the last time I’m in Yankee Stadium. I played there, I coached there and I was a general manager there. It’ll be fun for me. I’m appreciative that they asked.”

This was the second time former Yankees manager Joe Torre, now with the Dodgers, was bypassed by Hurdle and the NL.

Torre has said he didn’t mind not being picked for the game and thought he might be a distraction if he had been asked to attend.