Would it be best to go back to Lisbon and take the train to Porto?
This looks like the only train connection that does not go via Lisbon. It's faster than that option but with an additional change of train. Buses also appear to require a couple of connections
Obidos dep 11:03 R 6407 Direction: Caldas da Rainha
Caldas da Rainha arr 11:09
Transfer time 6 min.
Caldas da Rainha dep 11:15 IR 803 Direction: Coimbra-B
Alfarelos arr 12:55
Transfer time 24 min.
Alfarelos dep 13:19 IC 523 Direction: Porto(Campanha)
Subject to compulsory reservation
Porto(Campanha) arr 14:39
Duration: 3:36; runs daily
You may find this map helpful - https://www.cp.pt/StaticFiles/Passageiros/3_viajar/0_servicos/diagrama_servicos.jpg
Once you are in Coimbra, there are numerous trains to Porto. One hour trains every 2 hours alternating with slower 2 hour trains every 2 hours. See cp.pt
I would buy 2 tickets: one from Obidos to Coimbra and the other from Coimbra to Porto.
If you sign up on the Comboios Portugal website AND buy your ticket at least 8 days in advance, you can save money.