How do I bring a page template into a new theme with separate styling?

I currently have a page template that I have striped of all major styling within a theme (twentyninteen-child). I have a

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.

Share Improve this question edited Sep 24, 2019 at 1:03 jesstp asked Sep 20, 2019 at 9:37 jesstpjesstp 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

The 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;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745135396a4613175.html

相关推荐

  • How do I bring a page template into a new theme with separate styling?

    I currently have a page template that I have striped of all major styling within a theme (twentyninteen-child). I have a

    1小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信