• I would like to implement function to .site-title .
    I expect it will change color dynamically.

    What is a proper way to call function and apply that to class=”site-title”
    randomColor(); // Returned a random color as a hex string

    to call java-script function

Viewing 1 replies (of 1 total)
  • This should work. Try adding to a post or page to test:

    <script>
    jQuery(document).ready(function($) {
      r = Math.floor(Math.random() * (256));
      g = Math.floor(Math.random() * (256));
      b = Math.floor(Math.random() * (256));
      $('#site-title a').css('color', 'rgb('+r+','+g+','+b+')' );
    });
    </script>

    This works if your theme implements the site-title as a an ID, so if your theme has it as a class you’ll need to update your CSS selector as necessary.

    Also, once you have this working you should add it to a JS file and enqueue it if you want it to apply to all pages.

Viewing 1 replies (of 1 total)
  • The topic ‘How to apply java-script function to title?’ is closed to new replies.