Add custom styles to header or footer

I have a writer document where in addition to the standard headings, I’ve added my own custom styles, namely Year and Month. I’d like these to be displayed in the headers and footers. My starting point is as described here: Inserting a Chapter Name and Number in a Header or a Footer. However, I don’t see an option to add my own ‘Year’ and ‘Month’ styles.

Windows 10. LO version

By ‘Heading’ I mean the standard paragraph styles i.e. ‘Heading 1’, ‘Heading 2’ etc.
The ‘Year’ and ‘Month’ are also paragraph styles, created from the paragraph styles drop-down menu, then select ‘More Styles’ and then in the pane on the RHS, right-click → New…
I have the ‘Year’ style inheriting from ‘Heading 1’ and ‘Month’ inheriting from ‘Heading 2’. Both are set to ‘Custom Styles’.

There seems to be something special about the options that are available by default, i.e. Author, Chapter, Date filename, page number etc. I was hoping there would be a way to add to that list.

Please edit (= modify) your question to make it clearer. Don’t forget to mention OS name, LO version and save format.

Note that a heading is a “chapter” or other outline title inside the body of a document. A header is some fixed line repeated at top of every page. So, please, clarify.

What are your “custom styles” Year & Month? Are they paragraph or character styles? Do you mean in fact some document properties recorded in File>Properties?

The simplest way to add such data is to type them manually in the header or footer. Of course if you have many different page styles, it is more user-friendly to used fields to insert them. But, for that, describe the exact nature of Year and Month.

The OOO Development Tools (OooDev) project has vast support for headers and footer in Writer.

I have not as of yet documented the header and footer help files.
Howerver you can see the API Docs for header and footer formatting. The options are quite extensive.

Also you can review the test for header and footer to get an idea how they work.

Also see test for modifing styles of Headers and footers.

Example Code:

height = UnitMM100.from_mm(10.0)
spacing = UnitMM100.from_mm(3.0)
m_left = UnitMM100.from_mm(1.5)
m_right = UnitMM100.from_mm(2.0)

footer = Footer(
style = Color(StandardColor.YELLOW_LIGHT2)
font = Font(b=True, color=StandardColor.RED_DARK3, size=16)
Write.set_footer(text_doc=doc, text="Footer", styles=[footer, font, style])