GetSimple Support Forum
Including extra CSS/JS to header page level instead of new template - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: Feature Requests (http://get-simple.info/forums/forumdisplay.php?fid=7)
+--- Thread: Including extra CSS/JS to header page level instead of new template (/showthread.php?tid=2851)



Including extra CSS/JS to header page level instead of new template - acasperw - 2012-03-02

Hey there,

Would it be be possible to add CSS ( <link> or <style> ) to the header on a page level, instead of having to create a new template?

JS too, but not as necessary as this can be done inline currently, however <link> or <style> wont validate if it is in the body tag.


Sure you could have it included in the template from the beginning, however, if its only required on one page, ie, a gallery page or video page, to save on loading times, you don't want to include it in the global template.

So now you need to make a clone of the template, adding in the local <link> to the style-sheet.


Including extra CSS/JS to header page level instead of new template - mvlcek - 2012-03-02

acasperw Wrote:Would it be be possible to add CSS ( <link> or <style> ) to the header on a page level, instead of having to create a new template?

You can use I18N Custom Fields or I18N Special Pages to define an additional text/textarea field header for the pages, add the corresponding <link> or <style> into this field, if needed and include it in the template with get_custom_field('header') or get_special_field('header').


Including extra CSS/JS to header page level instead of new template - acasperw - 2012-03-02

mvlcek Wrote:
acasperw Wrote:Would it be be possible to add CSS ( <link> or <style> ) to the header on a page level, instead of having to create a new template?

You can use I18N Custom Fields or I18N Special Pages to define an additional text/textarea field header for the pages, add the corresponding <link> or <style> into this field, if needed and include it in the template with get_custom_field('header') or get_special_field('header').

Thanks !


Including extra CSS/JS to header page level instead of new template - n00dles101 - 2012-03-02

No need to install a plugin just to do this.

Just put a conditional statement in the header of your template like so: $id is the slug name.

Code:
<?php if ($id=='index' ){ ?>
<script type="text/javascript" src="<?php get_theme_url(); ?>/js/yourscriptfile.js"></script>
<?php } ?>


EDIT

Although you should probably use the built in functions to get the slug name, so this will also work.

Code:
<?php if(return_page_slug()=='index' ){ ?>
<script type="text/javascript" src="<?php get_theme_url(); ?>/js/yourscriptfile.js"></script>
<?php } ?>



Including extra CSS/JS to header page level instead of new template - alienee2 - 2012-04-19

I needed a way to load predefined scripts and css into the header and footer on a per page basis;

to make it easy, first i setup each set of scripts and css as unique components;

for example this component is called "prettyphoto-header":

Code:
<link rel="stylesheet" media="all" href="<?php get_theme_url(); ?>/style/css/prettyPhoto.css" />
    <script type="text/javascript" src="<?php get_theme_url(); ?>/style/js/quicksand.js"></script>
    <script type="text/javascript" src="<?php get_theme_url(); ?>/style/js/portfolio.js"></script>
    <script type="text/javascript" src="<?php get_theme_url(); ?>/style/js/jquery.prettyPhoto.js"></script>

then i created custom fields called "headercomp" and "footercomp" both as type dropdown box, and then listed all of the relevant components (leaving the first line blank so it defaults to nul);

then in each page, you can select any of the header/footer code (in the components) to load;

in the theme file, i put this in the head:

Code:
<?php $headercomp = return_custom_field('headercomp'); ?>
<?php get_component($headercomp); echo"\n" ?>

and this in the footer

Code:
<?php $footercomp = return_custom_field('footercomp'); ?>
<?php get_component($footercomp); ?>

it works great...!

Only issue is that i'm not sure if the php code is optimal; it does work, but if any php gurus out there know of a better way to code those tags, let me know!

-marc