最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - Help with showing text when something is entered in my search bar

programmeradmin2浏览0评论

I'm having troubles replacing text when there is something entered in the search form. As you can see in the image below i want to replace 'mijn gemeente' with the get_search_query text if i'm searching something, if nothing is searched it should show 'mijn gemeente'.

I'm having troubles replacing text when there is something entered in the search form. As you can see in the image below i want to replace 'mijn gemeente' with the get_search_query text if i'm searching something, if nothing is searched it should show 'mijn gemeente'.

Share Improve this question edited May 7, 2019 at 10:34 tru.d 1861 gold badge1 silver badge17 bronze badges asked May 7, 2019 at 9:33 DennisDennis 216 bronze badges 3
  • where is your search input? show the code, sharing snapshot of the code makes us to help more difficult – Vishwa Commented May 7, 2019 at 9:49
  • Search input is in my sidebar. I can get the text from the input and show it but i want it only to show if there was anything searched. When there is nothing searched it should show 'mijn gemeente'. So basically i need some sort of IF loop i think. – Dennis Commented May 7, 2019 at 10:04
  • I found it out, thanks for the help though. :) – Dennis Commented May 7, 2019 at 10:15
Add a comment  | 

1 Answer 1

Reset to default 0

You can do that using jQuery's focus function. add following into your php file inside <script> tags.

$("#your-searchinput-id").focus(function() {
    $("h4.title_sidebarsub").text("<?php echo $string ?>")
});
$(this).blur(function() {
    $("h4.title_sidebarsub").text("mijn gemeente")
});
发布评论

评论列表(0)

  1. 暂无评论