howto_user (howto_user) wrote in s2howto,

[paidaccount] Using print_custom_head()

Paid Accounts Only
The following tutorial requires creating and editing a custom style, which in turn requires a paid, permanent, or early adopter account. Please read What are the paid account benefits? and How do I buy a paid account? to learn about the paid account benefits and how to buy a paid account.

Cascading Style Sheets (CSS) allow you to change a lot of things in your journal. All of the system layouts support the ability to enter your custom CSS. However, if you are using a custom layout that doesn't have such an option, or if you would like to use different CSS on different page views, you can use print_custom_head() method in a custom theme layer.

The print_custom_head() method allows you to enter custom content into the <head> section of your journal, which can also be used to change the browser title or favicon for your journal, or add <meta> tags. Furthermore, you can choose to have different <head> content depending on the view of your journal (recent entries, friends page, calendar, etc.).

Note that the only HTML elements that can be used in print_custom_head() are those elements that are valid in the head of a HTML document. This is limited to <title>, <base>, <style>, <link>, and <meta>. All other elements are stripped.

The basic usage format of the print_custom_head() method is as follows:

function Page::print_custom_head() {
Your desired HTML elements

You will need to replace Your desired HTML elements with the actual HTML. For example, the following code will add a <meta> tag of the type required by Google for site ownership verification, and change the font to a 14 point Times New Roman font:

function Page::print_custom_head() {
<meta name="verify-v1" content="unique-string"> <style type="text/css"> p, td, body { font: 14pt Times New Roman, sans-serif; } </style>
"""; }

If you wish the code to be applied only to a particular page view, you can also replace Page with the appropriate child class (e.g. RecentPage, FriendsPage, YearPage, etc.).

The specific function that you define such as function Page::print_custom_head() can be used only once in your custom layer, however you can combine several elements into the same function as illustrated above and in a separate tutorial.

Tags: * basic tutorials, paid accounts only

Comments for this post were disabled by the author