开发者

function.php in wordpress. how do i insert html string in the head section?

开发者 https://www.devze.com 2023-03-25 23:31 出处:网络
I want to target an html element (<link> & <script>) and wrap it with an html comment string (<!-- -->).

I want to target an html element (<link> & <script>) and wrap it with an html comment string (<!-- -->).

from this:

<link href="somecss" rel="stylesheet" />
<script src="somejs" type="text/javascript"></script>

to this

<!-- <link href="somecss" rel="stylesheet" /> -->
<!-- <script src="somejs" type="text/javascript"></script> -->

I know this can开发者_如何学Python be done in the frontend using some javascript/jquery, But I wanted to do it in the backend using the function.php of wordpress. Any ideas how?

Thanks!


If you want to prevent loading wordpress scripts you should use wp_dequeue_script( $handle ) function. If can find description of $handle (default wordpress scripts) here.

If you want to prevent loading wordpress styles you should use wp_dequeue_style( $handle ) function.

You should use this function after wordpress add default script and styles. You can use hook wp_enqueue_script with high priority param (so it runs last): add_action('wp_enqueue_scripts', 'my_enquue_scripts', 100);

If your main theme have hardcoded scripts and styles in header.php - then you cannot prevent loading from functions.php

0

精彩评论

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