Add header news title scrolling wp

Here's a step-by-step guide on how to add a scrolling news title header in WordPress:

Method 1: Using a Plugin

  1. Install and activate the "Header & Footer Scripts" plugin from the WordPress plugin directory.
  2. Go to Settings > Header & Footer Scripts and click on the "Add New" button.
  3. In the "Header" section, add the following code:
    <script>
    jQuery(document).ready(function($) {
     var header = $('#header');
     var title = $('#header.title');
     var interval = setInterval(function() {
       title.animate({left: '-100%'}, 1000, function() {
         title.css('left', '0');
       });
     }, 5000);
    });
    </script>
  4. In the "Footer" section, add the following code:
    <style>
    #header.title {
     position: relative;
     left: 0;
     transition: left 1s;
    }
    </style>
  5. Save the changes.

Method 2: Using Custom CSS and JavaScript

  1. Add the following CSS code to your theme's stylesheet (style.css):
    
    #header.title {
    position: relative;
    left: 0;
    transition: left 1s;
    }

header.title.scrolling {

left: -100%; }

2. Add the following JavaScript code to your theme's functions.php file:
```php
function add_scrolling_header() {
 ?>
  <script>
    jQuery(document).ready(function($) {
      var header = $('#header');
      var title = $('#header.title');
      var interval = setInterval(function() {
        title.addClass('scrolling');
        setTimeout(function() {
          title.removeClass('scrolling');
        }, 1000);
      }, 5000);
    });
  </script>
  <?php
}
add_action('wp_footer', 'add_scrolling_header');
  1. Save the changes.

Method 3: Using a Theme Function

  1. Create a new file in your theme's directory called functions.php.
  2. Add the following code to the file:
    function scrolling_header() {
    ?>
    <script>
     jQuery(document).ready(function($) {
       var header = $('#header');
       var title = $('#header.title');
       var interval = setInterval(function() {
         title.animate({left: '-100%'}, 1000, function() {
           title.css('left', '0');
         });
       }, 5000);
     });
    </script>
    <?php
    }
    add_action('wp_footer', 'scrolling_header');
  3. Save the changes.

In all methods, you'll need to add the following HTML code to your theme's header.php file:

<header id="header">
  <div class="title">Your News Title Here</div>
</header>

This will create a scrolling news title header that changes every 5 seconds. You can adjust the animation speed and interval to your liking.