开发者

wordpress function: using str_replace to strip css in head

I'm currently trying to delete/comment a markup of in the head section of wordpress.

Here's my function.

function strip_style() { ?>
    <?php

    $commented_style = str_replace("<link rel="stylesheet" type="text/css" href="http://localhost/wp-content/themes/headway-208/style.css" />", "<!-- <link rel="stylesheet" type="text/css" href="http://localhost/wp-content/theme开发者_Go百科s/headway-208/style.css" /> -->", $rawstring);

    echo commented_style;

    ?>
<?php
}

add_action('wp_head', 'strip_style', 1);

I can't also use wp_enqueue_style and wp_deregister_style since the line i am trying to remove is hard-coded with the parent theme.

Basically I want to disable the default css (styles.css) its loading so I can use my own style and not override the default style.

Please advice if my approach of using str_replace() is good or not. Can you suggest an alternative?

Thanks!


Just copy header.php file in your child theme and edit out what you do not want to appear. If you have header.php in both child and parent theme, the one in child theme will be used. That counts for all files. If you want to edit any of parent theme files just copy it into child theme and edit them there.

As far as css is conserned, in head first the parent theme style.css will be linked and below it child theme style.css so every rule with same specificity in child theme will override parent theme rule, no need for any mambo-jumbo dirty magic.


Maybe I'm not fully understanding, but why don't you just copy the existing theme folder, rename it and make your own theme by wiping the style.css and start again as you want?

In any case, if you must do the str_replace(), your code is all wrong. Firstly, your PHP tags are all over the place, and you can't nest them. Secondly, your strings won't parse properly because you are using double quotes inside a double-quoted string. Fixed and simplified:

<?php

function strip_style() {
    $link = '<link rel="stylesheet" type="text/css" href="http://localhost/wp-content/themes/headway-208/style.css" />';
    echo str_replace($link, '<!-- ' . $link . '-->', $rawstring);

    // But where does $rawstring come from?
}

?>

.

<?php

    add_action('wp_head', 'strip_style', 1);

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜