It was only a matter of time, but the “selfie” culture has made its way into the ballot box. 

The rising popularity of "ballot selfies" -- voters taking photos of themselves or their ballots while at the polls -- is now creating a legislative headache for states, many of which have laws on the books restricting voters from sharing ballot information or images. 

The laws generally are meant to protect voter privacy, and also curb "vote-selling" and other schemes where photos can be used as proof for transactions.

But the decades-old rules clash with modern social media culture -- this flared up again last week, when House Speaker Paul Ryan’s failed primary challenger, Paul Nehlen, tweeted a picture of a ballot with his name marked off.

Wisconsin law technically prohibits these kind of photos. The Nehlen picture resulted in police in his hometown of Delavan looking into the matter; they plan to coordinate with the local district attorney’s office on whether to pursue charges.

Meanwhile, other states across the country are wrestling with how to handle voters -- even candidates -- who feel compelled to share their moment at the ballot box with the world. 

According to the most recent information from the Digital Media Law Project, at least 30 states clearly prohibit the disclosure of ballots. The laws vary widely, but several -- including Arizona, California, Colorado, Illinois, New Jersey and New York -- explicitly bar the photographing or filming of marked ballots.

In California -- where Kim Kardashian famously used Instagram to post her absentee ballot for the 2012 White House race to rally voters to the polls -- a Bay Area lawmaker is trying to amend state law to make similar selfies legal.

“Passing this bill is important to protect First Amendment freedom of speech rights and encourage a culture of voter participation,” Assemblyman Marc Levine, a Democrat and the bill’s sponsor, told FoxNews.com on Monday.

Kardashian avoided scrutiny by posting a blank ballot. But Levine’s bill, which has had bipartisan support and is expected to get final passage in the state Senate this week, would legalize the taking and posting of all ballot selfies including marked ones.

The bill would then go to Democratic Gov. Jerry Brown, whose office said Monday it does not comment on pending legislation.

Levine, in sponsoring the bill, cites recent federal court decisions that he thinks indicate California law on ballot selfies is likely unconstitutional, by denying voters their free-speech rights.

To be sure, a federal judge in Indiana promptly struck down a July 2015 law making ballot selfies a felony, disagreeing with the state’s argument that the statute deters so-called “vote selling” -- voting for a particular candidate or ballot measure in exchange for cash, then proving such with a photo.

And a federal judge in New Hampshire made a similar ruling last year, striking down a state law banning selfies and an accompanying $1,000 fine, on First Amendment grounds.

Both decisions are now in the appeals process.

New Hampshire Secretary of State William Gardner is appealing the decision in federal court, with social media powerhouse Snapchat getting behind the effort to continue to allow such selfies.

The case is scheduled for oral arguments starting Sept. 13, with a final decision expected several months later, the court said Monday.

Gardner has made an argument similar to that of Indiana, about voter coercion and vote buying and selling -- though at a more extreme level.

“If somebody wants to go out and say that they voted for this person or that person, they can do it. They can do it. But that ballot is sacred,” Gardner, the state’s top election official since 1976, told NPR in February 2015. “I have a copy of the last ballot that was used when Saddam Hussein was elected. And that ballot identified who the person was. Hitler did the same thing in Austria.”

Jessica Levinson, a professor at Loyola Law School, recently told The Los Angeles Times that California’s ban on ballot selfies is indeed problematic in the digital age. However, she thinks changing it might have the unintended consequence of making it easier for organizations or employers to pressure voters.

“An employer could say, ‘Oh, we’re all voting for this today, really looking forward to seeing your ballot on Facebook later,’ ” said Levinson, who specialized in election law and questions the argument that allowing the selfies will increase California voter turnout.