Wordpress alternate css file to working - css

Hi everyone for the help in advance: Im trying to get a 2nd header added to a custom temp page and in that alternate header all an alternate css file different from style.css.
I called the custom header from the cat template page like this
<?php get_header('header_state'); ?>
It works fine and places the header on the page and I called the css file in this custom header like this:
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>//localhost:8888/cnb_press/wp-content/themes/cnb-zip1/state_style.css" media="screen" />
but my page is still accessing the index.php style.css for some reason. I am on a MAMP and not live.
Any ideas why I am not getting this right?

If your page is still showing the incorrect CSS link tag, you aren't loading the new header template you created. WordPress wouldn't redirect an absolutely URLed CSS file referenced in the header.
Look at the WordPress template hierarchy to make sure your page is loading the template you think it is:
http://codex.wordpress.org/Template_Hierarchy

Related

Linked Stylesheet in WordPress

I am trying to build a second .css file for my company's website.
Currently, we are using a responsive theme, so most of our content displays correctly on desktop and mobile browsers. However, recently the boss is requesting custom code that is unresponsive. In order to keep the site looking good, I want to apply a secondary stylesheet that contains formatting for mobile devices. It would be like this for any html page:
<link rel="stylesheet" href="http://domain.tld/mobile.css" type="text/css" media="handheld" />
I cannot figure out how to get this into a wordpress child theme correctly. Can anyone offer suggestions?
Thank you in advance.
Look for the header.php file in your child theme directory, or under "Appearance"->"Editor" in the main menu of the your Wordpress adminpanel. You can paste the link to your new stylesheet there.
Also consider moving the styles to your theme's directory and replacing the domain in your href with <?php echo get_stylesheet_directory_uri(); ?> (example from wordpress codex).

How to get magento header in wordpress

I am having word press installed in side a sub directory of magento like
---Magento
----wp
--Blog (This is word press directory)
In word press we have header.php in theme folder.There I am trying to access the magento header block.
I am able to get this following way(Below code is written in head section of header.php of wordpress)
Mage::getLayout()->createBlock('page/html_head')->toHtml();
When I echo this I am able to get the magento header.But the css and js of magento application are not rendered as well the word press application is halting after rendering the content of magento. i.e nothing comes after header.
Please suggest me idea how can I get the css and js of magento application and the wordpress content properly?
The dirty way is to link Magento JS and CSS in your header.php file. like
<script type="text/javascript" src="<?php getSkinUrl('jsfolder/js.js') ?>"></script>
<link rel="stylesheet" type="text/css" href="<?php getSkinUrl('cssfolder/style.css') ?>">
There's actually a tweak in page.xml file but I wonder how, or why not to play it yourself?

How to link wp template to different stylesheet

I am trying have my own stylesheet linked to a custom page inside a theme on wordpress.
Im using this code on my header.php
/my-own-styles.css" />
There are 2 changes in this code that I made: 'my-template.php' and 'my-own-styles.css' nothing other then that. (Do I need to change the 'template_directory' too?)
inside the theme directory I have 'my-own-styles.css' but it doesn't seem to get it.
also I need it to get a .js file that I have put in the same directory but wouldn't work..
In WordPress, you need to hook your javascript and css includes onto the wp_enqueue_scripts action, and tell WordPress to load them using the wp_enqueue_style and wp_enqueue_script functions.
In your functions.php file, or any other file that will be loaded prior to the template file (say a plugin for example), add this:
add_action('wp_enqueue_scripts' , 'enqueue_my_scripts_and_styles');
function enqueue_my_scripts_and_styles() {
wp_register_style('my-own-styles.css',home_url('/').'wp-content/themes/**yourthemename**/my-own-style.css');
wp_enqueue_style('my-own-styles.css');
wp_register_script('my-own-js.js',home_url('/').'wp-content/themes/**yourthemename**/my-own-js.js');
wp_enqueue_script('my-own-js.js');
}
There are better ways to create the path to the file, but I wanted to provide an example that would be more obvious. For best practices, use get_template_directory_uri() http://codex.wordpress.org/Function_Reference/get_template_directory_uri
To link any page in wordpress whith a css file , just add this code in header.php
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/yourfile.css" type="text/css" media="screen" />
Where css is a a folder in your theme directory. You also can use the code with path directly to your file.

Custom WordPress Theme isn't picking up the style.css file

I have just followed a tutorial about creating custom WordPress theme, each and everything went just fine from static to dynamic conversion but when I activate that theme and I come up with a plain HTML document with blue hyperlinks which mean the site is not picking up the css file of style.css
Am I doing something wrong? Please help me.
Check your source HTML and see that the path to your CSS is correct.
You can use bloginfo() to find the correct path by using:
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/style.css">
If your style.css resides in the root folder of your template.
Where did you add the link to the file? - View the source of the page to see if the link is there and try navigating to it to see if it returns a 404 (Not Found) or other error.
My preferred way to include theme stylesheets is adding something like this to my functions.php.
add_action('wp_enqueue_scripts','enqueue_my_styles_scripts');
function enqueue_my_styles_scripts() {
wp_enqueue_style('my-styles',get_stylesheet_directory_uri().'/style.css');
}
Check out wp_enqueue_style and make sure you have a wp_head() call in your header file

How can I set the main theme-font dynamically, in WordPress

I have created a theme where I already have a custom options page where I let the user set text for footer, twitter user and some other things and that works well.
Now i'd like to add the functionality of letting the user that installed the theme select which font that should be used for content on the site. How can i accomplish this? I can probably create a php file that outputs something like:
<style type="text/css">
body{
font-family: <?php echo get_option('my-font');?>;
}
</style>
and include that file in header.php, but that means that I have to hit php for every request for this css and I want to avoid that if posssible.
Actually, I'd recommend placing that code directly in your header.php file. You'll already be parsing PHP code, so there's no reason you can't parse that get_option() request at the same time. I've used a similar system to generate a random header image on each page load based on WordPress options before as well.
For one theme I built, there were CSS options aplenty, so I decided to generate static CSS files when the user made changes. To get around caching, I would store the timestamp of the last update, and echo it out as a parameter in the CSS URL;
<link rel="stylesheet" type="text/css" href="/path/to/generated/css.css?ver=<?php form_option('theme_name_css_timestamp'); ?>" />

Resources