G
G
ggok2020-03-03 17:31:04
JavaScript
ggok, 2020-03-03 17:31:04

How to include javascript + jQuery in wp?

Hello.
I need to hide part of the text in the articles for this I found this script:
How to hide part of the text?
https://jsfiddle.net/webirus/k058u9ct/ I

created a file with the js extension, pasted it there

$(document).ready(function(){

    $('.button').click(function(){
        $('.block').toggleClass('opener');
        if (!$(this).data('status')) {
            $(this).data('status', true).html('Скрыть блок');
        } else {
            $(this).data('status', false).html('Показать блок');
        }
    });

});


I inserted the following line in the header:
<script type='text/javascript' src='http://dev.com/wp-content/themes/gridbox/assets/js/file.js'></script>


CSS corrected, finished off the blocks in the layout, part of the text is hidden, but the expand text button does not work.
By default, in the source code, I see that jquery is included:
<script type='text/javascript' src='http://dev.com/wp-includes/js/jquery/jquery.js?ver=1.12.4-wp'></script>
<script type='text/javascript' src='http://dev.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1'></script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-03-03
@ggok

https://wp-kama.ru/function/wp_enqueue_script

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question