• Hello, I’m trying to apply unique CSS code to one of my wordpress pages. Although I can do this on a global scale using style.css or in-line for each html elements, I would like to add the <style> tag to one of my wordpress pages before the <body> sections.

    Problem is, when using the wordpress text-editor, it doesn’t show the full script (e.g., <!DOCTYPE html> <html> <head>), just the code that would go in the <body></body> tags.

    I could download/upload the file via FTP and change it manually, but I will need to edit this page regularly. I have a feeling if I edit the page through the wordpress editor, it will overwrite my manual changes.

    Any way I can get around having to use external style sheets or in-line styling?

    • This topic was modified 9 years, 8 months ago by rooshio.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Wordpress editor will remove style tags anyway when saved. It’s not a very good way to do things.

    You have two options:

    1. Quick, easy and dirty: Use a plugin like https://en-au.ww.wp.xz.cn/plugins/add-code-to-head/ (Never used it so unsure how flexible)

    2. Learn to use WordPress hooks and filters and you can add something like the following to your functions.php file:

    
    // 'before' hook is available at top of spacious theme
    add_action('before', 'add_my_code', 10, 2); 
    function add_my_code() {
        $my_code = <<<EOT
    <style>
    .body { background: white; }
    </style>
    EOT;
    
    CurrentPageID = get_the_ID();
    if (CurrentPageID == '123' ) : //apply only to post with ID = 123
        echo $my_code;
    endif;
    }
    Thread Starter rooshio

    (@rooshio)

    Thanks Shannon! Very helpful!

    No Problem

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Accessing the HEAD tag: Using internal style sheets with wordpress editor’ is closed to new replies.