• 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 15 replies - 1 through 15 (of 25 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You’ll have to show us a page with the issue

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Actually I didn’t see the screenshot of the error.

    Can you create a PasteBin file with the contents of your ‘typed.js’ file? Then link us that.

    • This reply was modified 7 years, 9 months ago by Andrew Nevins.
    Thread Starter Phillip Dews

    (@phillipdewsblogger)

    Hi Andrew,

    thank you for the quick reply. I have never used pastebin or any other service like that before. I have (I think correctly) created a fiddle here: https://jsfiddle.net/jyxa51vy/

    Many thanks.
    Phillip

    Thread Starter Phillip Dews

    (@phillipdewsblogger)

    opps sorry her is another link https://jsfiddle.net/jyxa51vy/3/

    • This reply was modified 7 years, 9 months ago by Phillip Dews.
    Thread Starter Phillip Dews

    (@phillipdewsblogger)

    Just made another fiddle and added typed.js as an external resource fella. Here is the link..
    https://jsfiddle.net/jyxa51vy/6/

    Thanks again

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    The HTML is slightly off in the jsFiddle example:

    
    <span id="typing style=white-space:pre"></span></h1></section>
    

    Try this instead:

    
    <span id="typing" style="white-space:pre"></span></h1></section>
    
    Thread Starter Phillip Dews

    (@phillipdewsblogger)

    Hmm that’s working after a fashion as you can see here https://jsfiddle.net/jyxa51vy/10/ but the typed-strings are not showing though weirdly when it should be those that are being typed out

    Have put your fix in the actual theme as well but nothing is typing there weirdly and I am still getting the….
    TypeError: $(...).typed is not a function
    in the console

    Many thanks

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I noticed that you’re mispelling the ‘stringsElement’ option slightly. It doesn’t have an ‘s’ on the end. That then generates an error in the console for that jsFiddle but at least we’re progressing.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Have put your fix in the actual theme as well but nothing is typing there weirdly and I am still getting the….
    TypeError: $(…).typed is not a function
    in the console

    That would suggest the typed.js file isn’t loading properly.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Try this: https://jsfiddle.net/jyxa51vy/15/

    Do you see the difference?
    According to the docs, the strings must each be wrapped in a paragraph and the option must take a jQuery object: https://github.com/mattboldt/typed.js/blob/master/README.md

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    In your WordPress template, put this script right at the bottom of the template:

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

    Note it has to be before the </body> tag

    • This reply was modified 7 years, 9 months ago by Andrew Nevins.
    Thread Starter Phillip Dews

    (@phillipdewsblogger)

    We certainly are Andrew, many thanks. I’m surprised that it’s not loading properly as I ma calling it correctly. here is the link to that direct file…

    https://www.monkeypantsproductions.co.uk/wp-content/themes/monkeypants/js/typed.js

    I have also updated the fiddle with the s removed as suggested but still the same https://jsfiddle.net/jyxa51vy/14/

    Appreciate all the help Andrew.

    Thread Starter Phillip Dews

    (@phillipdewsblogger)

    OK have redone everything in your fiddle on the theme and wrapped them in <p> tags but still getting the error weirdly when it’s working perfectly fine in the fiddle!

    getting there though I see, turning into quite a challenge hey!

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Did you manage to move the following script to the bottom of the template:

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

    (@phillipdewsblogger)

    Certainly did, I put it just above the <?php get_footer(); ?> in that template file!
    Want me to try it in the footer itself? I also moved the link to the typed.js file just above it to the file now looks like this…

      <section id="section2">
        <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">
          <p>Phrase or Sentence 1</p>
          <p>Phrase or Sentence 2</p>
          <p>Phrase or Sentence 3</p>
        </section>
      </section>
    </div>
    <script src="<?php echo get_template_directory_uri(); ?>/js/typed.js" type="text/javascript"></script>
    <script type="text/javascript">
      $(function(){
        $("#typing").typed({
          stringElement:$("#typed-strings"),
          typeSpeed:30,
          backDelay:500,
          loop:true,
          showCursor:true,
        });
      });      
    </script>

    I will try it in the footer.php instead and see if that makes any difference!

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