I currently have a page template that I have striped of all major styling within a theme (twentyninteen-child).
I have a new child theme (event), that this page/template will sit under and am having trouble incorporating it. There are so many posts that say different things, I am getting confused and have crashed my UAT multiple times.
The page will sit separate from the site and will not (at this time) have a header or footer of the larger site that it will sit in. Below is the code that partially works.
<?php /* Template Name: My template */ ?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
<?php function mypage_head() {
echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('stylesheet_directory').'/css/style.css">'."\n";
}
add_action('wp_head', 'mypage_head');
?>
</head>
<body class="page-template-connect-home-placeholder">
Is this what I should be doing if I want a page template to have completely different styling to the rest of the site?
EDITED:
After trying quite a few things I have just referenced the other themes styling in the template. It's probably not the best way of doing it, but it works. I used the <link rel="stylesheet" href="">
and removed the <?php wp_head(); ?>
tag. I need to update the style in the other section as it was thrown out a bit, but can use the other theme fine.
I currently have a page template that I have striped of all major styling within a theme (twentyninteen-child).
I have a new child theme (event), that this page/template will sit under and am having trouble incorporating it. There are so many posts that say different things, I am getting confused and have crashed my UAT multiple times.
The page will sit separate from the site and will not (at this time) have a header or footer of the larger site that it will sit in. Below is the code that partially works.
<?php /* Template Name: My template */ ?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
<?php function mypage_head() {
echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('stylesheet_directory').'/css/style.css">'."\n";
}
add_action('wp_head', 'mypage_head');
?>
</head>
<body class="page-template-connect-home-placeholder">
Is this what I should be doing if I want a page template to have completely different styling to the rest of the site?
EDITED:
After trying quite a few things I have just referenced the other themes styling in the template. It's probably not the best way of doing it, but it works. I used the <link rel="stylesheet" href="">
and removed the <?php wp_head(); ?>
tag. I need to update the style in the other section as it was thrown out a bit, but can use the other theme fine.
1 Answer
Reset to default 0The problem is that your theme still load the main style.css sheet, because it is called by wp_head()
. See the documentation here
So, in order to not load your theme main stylesheet, you have to add to your functions.php
file :
add_action( 'wp_enqueue_scripts', 'yolo_my_custom_template' );
function yolo_my_custom_template(){
if ( is_page_template( 'name_of_your_page_template.php' ) ) :
wp_deregister_script('twentynineteen-style');
wp_deregister_script('twentynineteen-print-style');
endif;
}