0

I'm trying to toggle my search bar, for that I've a href tag and font-awesome icon.

Trigger works well when it is index.php, I mean home page.
It creates independently links to other pages and to home.
Trigger doesn't work when other pages is loaded ecxept home page.

I would like to disable it to be create or recognize other pages URL and to use it only for trigger for toggle.

For example: this script works only when my site's URL mywebsite.com is, but It won't work when URL so "mywebsite.com/a-random-page" is.

HTML

div class="messagepop pop">

  <?php get_search_form(); ?>
</div>
<a href="#" id="contact"><i class="fa fa-search"></i></a>

jQuery

// Show mobile-menu > 700
$(window).resize(function() {
  if ($(window).width() > 800) {
    $(".messagepop").hide();
  }
});

function deselect(e) {
  $('.pop').slideFadeToggle(function() {
    e.removeClass('selected');
  });    
}

$(function() {
  $('#contact').on('click', function() {
    if($(this).hasClass('selected')) {
      deselect($(this));               
    } else {
      $(this).addClass('selected');
      $('.pop').slideFadeToggle();
    }
    return false;
  });

  $('.close').on('click', function() {
    deselect($('#contact'));
    return false;
  });
});

$.fn.slideFadeToggle = function(easing, callback) {
  return this.animate({ opacity: 'toggle', height: 'toggle' }, 'fast', easing, callback);
};
DaF-Student
  • 39
  • 1
  • 7
  • Have you got a hyperlink with an ID of `contact` on each of the other pages, and made sure to include the same jQuery script on all pages? – Obsidian Age May 25 '17 at 22:52
  • I've deleted with an ID of contact page and also call same jQuery script in all pages using wp_enqueue_script in functions.php. I was trying to implement this fiddle to my case: http://jsfiddle.net/SRw67/ – DaF-Student May 25 '17 at 23:03
  • @DaF-Student your fiddle works fine .. what is the problem?? – Mohamed-Yousef May 25 '17 at 23:24
  • @Mohamed-Yousef I would like to use this fiddle in my wordress site, but it doesn't work when other pages are loaded, except home, In short it works only in home page. – DaF-Student May 25 '17 at 23:28
  • may be this https://wordpress.stackexchange.com/questions/23041/wordpress-enqueue-for-homepage-only-functions-php-wp-framework help .. also take a look at https://stackoverflow.com/questions/2017755/whats-the-difference-between-e-preventdefault-and-return-false – Mohamed-Yousef May 25 '17 at 23:34
  • I'm loading javascript file with following function `// Enqueue Javascript files function arf_load_javascript_files() { if ( !is_admin() ) { wp_enqueue_script( 'arf_global', get_template_directory_uri().'/js/global.js', array('jquery'), '', true ); if ( is_singular() ) wp_enqueue_script( "comment-reply" ); } } add_action( 'wp_enqueue_scripts', 'arf_load_javascript_files' );` – DaF-Student May 25 '17 at 23:53

0 Answers0