简体   繁体   中英

How to first use custom script to page load in WordPress theme?

How can a custom script be used on a page and along with custom CSS and JavaScript in a WordPress plugin?

在此处输入图片说明

<script type="text/javascript">
        $(document).ready(function () {
            $('#iview').iView({
                pauseTime: 22000,
                directionNav: false,
                controlNav: true,
                tooltipY: -15
            });
        });
</script>

You just need to enqueue your scripts before other script loads. You can do it by setting priority to 0 for your hook. For example, do the following:

add_filter( 'wp_enqueue_scripts', 'enqueue_your_scripts', 0 );

function enqueue_your_scripts() {
    wp_enqueue_script( 'yourscript', 'URL', array( 'jquery' ) );
   //URL of js in which your custom code exist.
}

You can set priority of loading script by change number in add_filter,

reference: add filter in wordpress

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM