Studies of heavy flavour production in $pp$ collisions at the LHC both provide the means to verify the predictions of perturbative quantum chromodynamics (pQCD) and are crucial for an accurate description of background channels in Standard Model (SM) measurements and new physics searches. A wide program of studies of heavy flavour production at the LHC is performed by the ATLAS and CMS collaborations and their recent results in this field are reviewed in this paper.For the CMS collaboration, we report the measurement of differential prompt production cross sections of S-wave quarkonia in $pp$ collisions at $\sqrt{s}=13$ TeV and of production cross sections of $B_c^+$ ($\rightarrow J/\psi\pi^+$) and $B^+$($\rightarrow J/\psi K^+$) in $pp$ co...