A similar resolution is to use SetDelay (:>) : Range[10]^2 + 1 /. p_ /; PrimeQ[p] :> Framed[p]. SetDelay gives you more controls. ex. what if the condition is that $p-3$ is prime then I add frame to p ? You can do:
SetDelay
:>
: Range[10]^2 + 1 /. p_ /; PrimeQ[p] :> Framed[p]
p
Range[10]^2 + 1 /. p_ /; PrimeQ[p-3] :> Framed[p]
If[PrimeQ[#], Style[#, Red], #] & /@ (Range[25]^2 + 1)
NOT be: If[PrimeQ[#], Style[#, Red], #] & /@ Range[25]^2 + 1
Exercise for the interested student: use the following functions to solve this problem...
PrimeQ
Map
If
;-)