• Phillip Dews

    (@phillipdewsblogger)


    Hi all,

    I am building a custom theme for a new client and im trying to implement the awesome typed.js within the code of my theme. so this is what i have got in my code so far..

    In my header.php I am calling this…
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

    In my front-page.php where I want the typed.js to work I have this….

    <script src="<?php echo get_template_directory_uri(); ?>/js/typed.js" type="text/javascript"></script>
        <script type="text/javascript">
          $(function(){
            $("#typing").typed({
              stringsElements:("#typed-strings"),
              typeSpeed:30,
              backDelay:500,
              loop:true,
              showCursor:true,
            });
          });
        </script>
        <section id="typed-wrapper"><h1 class="welcome">Welcome to Monkeypants we: <span id="typing style=white-space:pre"></span></h1></section>
        <section id="typed-strings">
          <h2>Phrase or Sentence 1</h2>
          <h2>Phrase or Sentence 2</h2>
          <h2>Phrase or Sentence 3</h2>
          <h2>Phrase or Sentence 4</h2>
          <h2>Phrase or Sentence 5</h2>
        </section>
      </section>

    You can see my issues here with this screengrab.
    TypeError Issue

    Im assuming it’s a jQuery conflict but I know that I am only calling the 1 jquery cdn link as this is a custom built theme that I am developing from the groundup.

    Many thanks for any help.
    Phillip Dews

Viewing 10 replies - 16 through 25 (of 25 total)
  • Thread Starter Phillip Dews

    (@phillipdewsblogger)

    Tried in footer and still the same result Andrew!
    very weird indeed! I got it working perfectly on my own site of phillipdews.com but thats not built on wordpress like this is but I cannot see that making any difference though.

    Appreciate all the time your putting into this! I hope some other developers can get help from this thread.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    No need to move it further.
    Can you double-check what is being output by this:
    `
    <script src=”<?php echo get_template_directory_uri(); ?>/js/typed.js” type=”text/javascript”>

    Thread Starter Phillip Dews

    (@phillipdewsblogger)

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Would it be possible to take everything from your view-source and put it into jsFiddle, removing the client-sensitive parts?

    Thread Starter Phillip Dews

    (@phillipdewsblogger)

    Wow well nothing really sensitive but I have pasted everything here fella as it’s midnight and hitting the sac fella. Here is the fiddle with everything…

    https://jsfiddle.net/qeefuuu6/

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Okay I see an issue with the source code. There are 2 jQuery libraries being loaded. Only 1 must be loaded. I recommend you continue to use the jQuery version provided by WordPress and not try to load a different version.

    Your theme is probably enqueing WordPress’ jQuery library, so you need to properly enqueue the typed.js script file. The typed.js script file must be enqueued so that it is loaded after the jQuery library.

    Once that order has been achieved, the script that fires the typed.js code must be using “jquery noconflict” mode. This means that the dollar variable by default is undefined. This noconflict mode happens from the version of jQuery that WordPress uses.

    So you need to change that script to this:

    
    <script type="text/javascript">
          jQuery(function($){
            $("#typing").typed({
              stringsElements:("#typed-strings"),
              typeSpeed:30,
              backDelay:500,
              loop:true,
              showCursor:true,
            });
          });
        </script>
    

    Specifically changing this:

    
          $(function(){
    

    To this:

    
          jQuery(function($){
    
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Thread Starter Phillip Dews

    (@phillipdewsblogger)

    Morning Andrew,

    Thats great fella many thanks! One last thing though I have made the changes in the theme but the typed-strings are not typing and just the default ones. Here I have updated the latest fiddle..

    https://jsfiddle.net/qeefuuu6/1/

    Thanks again fella.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Remember the ‘stringsElement’ option takes a jQuery object:

    
    
          stringsElements:("#typed-strings"),
    

    Should be:

    
    
          stringsElements: $("#typed-strings"),
    
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Also, it’s not “stringsElements”. It’s “stringsElement”.

Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘TypeError issue’ is closed to new replies.