Sorry about still asking regarding this, this is after trying my best with the previous answers. Adding a stylesheet switcher function in functions.php has no effect, since wp_head() keeps applying the default stylesheet (style.css) anyway.
Adding:
add_action( 'wp_enqueue_scripts', 'customstyles' );
function customstyles() { echo "hello world";
if ( is_page('306') ) {
wp_enqueue_style( '306page', get_stylesheet_uri()); //page-specific css for unique page
}
else {wp_enqueue_style( 'styles', get_stylesheet_uri() ); } //default stylesheet
}
in the theme's functions.php and then calling <?php customstyles(); ?> from header.php has no effect, the default style.css still gets applied on all pages.
Tried removing wp_head() from header.php and leaving only the custom function in place, but then no stylesheet was being applied, which further proves that wp_head() is taking care of the linked css.
So how do you customize wp_head() so that it doesn't override stylesheets added via code in functions.php, or elsewhere? And why is the stylesheet code in functions.php being ignored in the first place? When testing with echo 'hello world' inside customstyles() hello world was output on the page, but the function's stylesheet code was ignored. Also WP_DEBUG is set to true and gives no errors.
EDIT:
This is the wordpress code in the head section, plus the custom function call:
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<?php if (is_search()) { ?>
<meta name="robots" content="noindex, nofollow" />
<?php } ?>
<title>
<?php
if (function_exists('is_tag') && is_tag()) {
single_tag_title("Tag Archive for ""); echo '" - '; }
elseif (is_archive()) {
wp_title(''); echo ' Archive - '; }
elseif (is_search()) {
echo 'Search for "'.wp_specialchars($s).'" - '; }
elseif (!(is_404()) && (is_single()) || (is_page())) {
wp_title(''); echo ' - '; }
elseif (is_404()) {
echo 'Not Found - '; }
if (is_home()) {
bloginfo('name'); echo ' - '; bloginfo('description'); }
else {
bloginfo('name'); }
if ($paged>1) {
echo ' - page '. $paged; }
?>
</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php customstyles(); ?>
<?php wp_head(); ?>
The default stylesheet actually applies on the generic pages as supposed to. It just doesn't apply the custom stylesheet on page '306'. But I've verified the stylesheet name which is correct in the wp_register_style( 'thisIsTheCustomStyleThatWontApplyButIsSpelledRightAndIsInTheSameDirectoryAsTheDefaultStylesheet', get_template_directory_uri() ) method. Added "/" to get_template_directory_uri(), which didn't solve it.
get_stylesheet_uri, WordPress will add style.css to the returned path. Codex states : The stylesheet file name is 'style.css' which is appended to get_stylesheet_directory_uri() path. codex.wordpress.org/Function_Reference/get_stylesheet_uri - Anand Shah