Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$10
Want to use specific CSS file for all single posts
Now we want ALL our posts, from any category, to use one of those css files, rather than the default style used on the homepage. But I'm not sure where and how to add some sort of call to use particular css within the single post php.
Most of the instruction I'm finding has to do with creating custom single post templates and assigning them through functions.php or elsewhere, which all seems like WAY too much for what we need, since our need is not category or post specific. We want ALL posts to use our steelblue.css, not just some of them.
Kayle | 08/15/12 at 9:29am
Edit
Tutorial: How to assign prize money
(9) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
08/15/12
9:32am -

Last edited:
08/15/12
9:39amAdamGold says:Add the following code to your functions.php:
function add_style_to_single()
{
if (is_single()) {
wp_enqueue_style('steelblue', 'path/to/steelblue.css');
}
}
add_action('wp_print_styles', 'add_style_to_single');Previous versions of this answer: 08/15/12 at 9:33am | 08/15/12 at 9:39am
- 08/15/12 3:38pm
Kayle says:Thanks but this caused my category blog page to look like this:
http://realfreshcreative.com/fractalscreen.jpg
Not sure why.
- 08/15/12 3:43pm
AdamGold says:I'm guessing you didn't put <?php before that syntax, here's the new one:
<?php
function add_style_to_single()
{
if (is_single()) {
wp_enqueue_style('steelblue', 'path/to/steelblue.css');
}
}
add_action('wp_print_styles', 'add_style_to_single'); - 08/15/12 4:00pm
Kayle says:Don't I then need a ?> at the end, as well, if I do that? My function.php is copied below; see the end of it. Is that correct now?
<?php
/**
* Sets up the theme by loading the Mysitemyway class & initializing the framework
* which activates all classes and functions needed for theme's operation.
*
* @package Mysitemyway
* @subpackage Functions
*/
if ( !function_exists( 'mysite_menus' ) ) :
/**
*
*/
function mysite_menus() {
register_nav_menu( 'primary-menu', __( 'Primary Menu', MYSITE_ADMIN_TEXTDOMAIN ) );
register_nav_menu( 'primary-menu-logged-in', __( 'Primary Menu Logged In', MYSITE_ADMIN_TEXTDOMAIN ) );
register_nav_menu( 'header-links', __( 'Header Links', MYSITE_ADMIN_TEXTDOMAIN ) );
register_nav_menu( 'footer-links', __( 'Footer Links', MYSITE_ADMIN_TEXTDOMAIN ) );
}
endif;
if ( !function_exists( 'mysite_primary_menu' ) ) :
/**
*
*/
function mysite_primary_menu() {
$out = '<div id="primary_menu">';
ob_start(); mysite_primary_menu_begin();
$out .= ob_get_clean();
if ( !is_user_logged_in() ) {
$out .= wp_nav_menu(
array(
'theme_location' => 'primary-menu',
'container_class' => 'jqueryslidemenu',
'menu_class' => ( !has_nav_menu( 'primary-menu' ) ? 'jqueryslidemenu' : ''),
'echo' => false,
'walker' => ( has_nav_menu( 'primary-menu' ) ? new mysiteDescriptionWalker() : '')
));
}
else
{
$out .= wp_nav_menu(
array(
'theme_location' => 'primary-menu-logged-in',
'container_class' => 'jqueryslidemenu',
'menu_class' => ( !has_nav_menu( 'primary-menu-logged-in' ) ? 'jqueryslidemenu' : ''),
'echo' => false,
'walker' => ( has_nav_menu( 'primary-menu-logged-in' ) ? new mysiteDescriptionWalker() : '')
));
}
$out .= '<div class="clearboth"></div>';
ob_start(); mysite_primary_menu_end();
$out .= ob_get_clean();
$out .= '</div><!-- #primary_menu -->';
echo apply_atomic_shortcode( 'primary_menu', $out );
}
endif;
# Load the Mysitemyway class.
require_once( TEMPLATEPATH . '/framework.php' );
# Get theme data.
$theme_data = get_theme_data( TEMPLATEPATH . '/style.css' );
# Initialize the Mysitemyway framework.
Mysitemyway::init(array(
'theme_name' => $theme_data['Name'],
'theme_version' => $theme_data['Version']
));
function my_custom_login_logo() {
echo '<style type="text/css">
h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif) !important; }
</style>';
}
add_action('login_head', 'my_custom_login_logo');
function change_wp_login_url() {
echo bloginfo('url');
}
function change_wp_login_title() {
echo get_option('blogname');
}
?>
<?php
// replace WordPress Howdy in WordPress 3.3
function replace_howdy( $wp_admin_bar ) {
$my_account=$wp_admin_bar->get_node('my-account');
$newtitle = str_replace( 'Howdy,', 'Welcome', $my_account->title );
$wp_admin_bar->add_node( array(
'id' => 'my-account',
'title' => $newtitle,
) );
}
add_filter( 'admin_bar_menu', 'replace_howdy',25 );
?>
<?php remove_filter ('the_content', 'wpautop'); ?>
<?php
function add_style_to_single()
{
if (is_single()) {
wp_enqueue_style('steelblue', 'http://fatfractal.com/beta/wp-content/themes/infocus/styles/steelblue.css');
}
}
add_action('wp_print_styles', 'add_style_to_single');
?>
- 08/15/12 4:03pm
AdamGold says:Yes it should work now. FYI, ?> is not needed :)
- 08/16/12 9:51am
Kayle says:Addition of the tag didn't help; still showing the code at top of blog page and not changing the css. I know the location of the css file I'm pointing to is correct; was there anything else I needed to alter in your code to work?
- 08/16/12 9:54am
AdamGold says:I am sorry, replace:
add_action('wp_print_styles', 'add_style_to_single');
With:
add_action('wp_enqueue_scripts', 'add_style_to_single');
- 08/15/12 3:38pm
-

Last edited:
08/15/12
9:34amDaniel Yoen says:put this lines to your header.php
<?php if(is_singular()) { ?>
<!-- your style here -->
<?php } ?>
complete guide :
http://codex.wordpress.org/Conditional_Tags -

Last edited:
08/15/12
9:39amNavjot Singh says:Add this line in your function.php
if(is_single())
{
function wp7088_style()
{
// Register the style like this for a theme:
wp_register_style( 'custom-style', get_template_directory_uri() . '/steelblue.css', array(), '20120815', 'all' );
// For either a plugin or a theme, you can then enqueue the style:
wp_enqueue_style( 'custom-style' );
}
add_action( 'wp_enqueue_scripts', 'wp7088_style' );
}Previous versions of this answer: 08/15/12 at 9:39am
-

Last edited:
08/15/12
9:40amAbdelhadi Touil says:Hi.
You can use AdamGold answer, or just paste this code in you header.php file:
<?php if (is_single()) { ?>
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_url'); ?>/single.css" />
<?php } ?>
single.css is the css file you want to use for single posts.
and you can find helpful informations here:
http://www.wpbeginner.com/wp-themes/how-to-style-each-wordpress-post-differently/
Good luck. -

Last edited:
08/15/12
12:35pmPali Madra says:I typically follow the rules laid down at http://www.wpbeginner.com/wp-themes/how-to-style-each-wordpress-post-differently/.
This does the job. However, if you need help give me a shout and I can do it for you. -

Last edited:
08/15/12
12:59pmArnav Joy says:in header.php find following line
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
and replace with
<?php if (is_single()) { ?>
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_url'); ?>/steelblue.css" />
<?php } else { ?>
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
<?php } ?>- 08/15/12 3:39pm
Kayle says:My header file doesn't have that line. I've notice with infocus theme, the header file seldom has anything anyone tells me to look for... they just don't do things the normal way, I guess. In any case I'm hoping to solve this using functions.php, as Adam said I could do...it's just that I pasted his code in and it caused problems, see response to him above. Thanks, though, for answering! I really do appreciate it.
- 08/15/12 3:39pm
-

Last edited:
08/15/12
2:41pmAsad Iqbal says:Custom page template is not so complex as you've a css already. If you are interested then I can make a page template for you. Custom page template is easy to use from admin panel and then you can use both, current template and new custom page template upon your wish.
- 08/15/12 3:40pm
Kayle says:I am not trying to do a custom PAGE template. I already have those. I am trying to assign some custom css to all single POSTS.
- 08/15/12 4:02pm
Asad Iqbal says:Can you please give me your site link?
- 08/15/12 3:40pm
-

Last edited:
08/15/12
4:20pmMartin Pham says:Please inset into functions.php
function load_custom_style() {
if(is_singular()) {
// Using for single post and all custom post type
wp_register_style( 'split-style', get_stylesheet_directory_uri().'/stylesheets_folder/steelblue.css' );
} else {
// Using for home - category ....
wp_register_style( 'split-style', get_stylesheet_directory_uri().'/stylesheets_folder/you_default_style.css' );
}
wp_enqueue_style( 'split-style' );
}
add_action('wp_enqueue_scripts', 'load_custom_style');
- 08/16/12 9:55am
Kayle says:Can you please indicate to me what i need to alter in this code ? For example, instead of stylesheets_folder, do I put a full uri of where the steelblue.css is located int that spot? I'm sorry but I need people to be very specific with me on things...
- 08/16/12 9:57am
Kayle says:also I don't want to use this style for the home page or the category page...just the single post pages.
- 08/16/12 11:11am
Martin Pham says:insert this into functions.php
function load_custom_style() {
if(is_singular()) {
// Only load it on single post and all custom post type
wp_register_style( 'split-style', get_stylesheet_directory_uri().'/styles/steelblue.css' );
wp_enqueue_style( 'split-style' );
}
}
add_action('wp_enqueue_scripts', 'load_custom_style');
What about:
get_stylesheet_directory_uri() : http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri
is_singular(): http://codex.wordpress.org/Function_Reference/is_singular - 08/16/12 11:37am
Kayle says:Thanks for the reference links. It looks like singular affects pages as well as posts; that would be problematic. I think perhaps single is more correct here.
- 08/16/12 11:43am
Martin Pham says:yes, if you dont want load it on page, you can use is_single()
function load_custom_style() {
if(is_single()) {
// Only load it on single post and all custom post type
wp_register_style( 'split-style', get_stylesheet_directory_uri().'/styles/steelblue.css' );
wp_enqueue_style( 'split-style' );
}
}
add_action('wp_enqueue_scripts', 'load_custom_style');
http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page
- 08/16/12 9:55am
This question has expired.
Kayle had additional discourse to offer.
Current status of this question: Community pot
Please log in to add additional discourse to this page.
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
