[Solved] Custom font (.otf) not being applied to headers and captions

Victor Asks: Custom font (.otf) not being applied to headers and captions
I am trying to use a custom font (.otf files) on a template document that I am building. I looked for different ways of doing so and am currently using the XeLatex compiler to create a new font family and I am trying to apply it to my entire document (that’s my goal, not to just use it for a certain part, but the whole thing).

The code and output that I am getting are:

Code:
...

usepackage{fontspec}
newfontfamilycoolfont[Path=config/CoolFont/,
  Extension=.otf,
  UprightFont=*-Regular,
  ItalicFont=*-RegularItalic,
  BoldFont=*-Bold,
  BoldItalicFont=*-BoldItalic
]{CoolFont}
...

begin{document}
coolfont
    
...
end{document}


Output

My problem is that the section header and the figure caption are not in the font I selected (the body text looks good, correctly applying bold and italics as well). This also happens for page numbers, table captions, etc. I have also tried calling the coolfont in the preamble, which just gave me an error and I tried using setmainfont, but that didn’t even change the body text font.

What is the best way to use custom font files to set a font for the whole document? (I am using Overleaf for this project)

Thank you so much for the help!

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.