I'm having trouble adding a shortcode directly to my theme.
The problem occurs with the short code.
Can someone help me?
Thank you!
[ihc-level-link id=1]
<div id="advc-menu" class="search">
<form method="get" id="searchform" action="<?php echo esc_url( home_url() ); ?>">
<input type="text" placeholder="Search..." name="s" id="s" value="<?php echo dt_clear($_GET['s']); ?>" autocomplete="off">
<button class="search-button" type="submit"><span class="icon-search2"></span></button>
</form>
</div>
[/ihc-level-link]
Use this code:
<?php
$html = '<div id="advc-menu" class="search">
<form method="get" id="searchform" action="'. esc_url( home_url() ) .'">
<input type="text" placeholder="Search..." name="s" id="s" value="'. dt_clear($_GET['s']) .'" autocomplete="off">
<button class="search-button" type="submit"><span class="icon-search2"></span></button>
</form>
</div>';
echo do_shortcode("[ihc-level-link id=1] ". $html ." [/ihc-level-link id=1]");
?>
Related
Hello I am newbie and I would like to ask how is it possible to change the placeholder depend on language?. I have a multilingual wordpress site and I wrote this code on a .php file :
<form class="search" id="searchform" action="<?php echo home_url(); ?>/" method="get">
<fieldset>
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search', 'alora'); ?>" />
</span>
</fieldset>
</form> `
I also tried this:
<form class="search" id="searchform" action="<?php echo home_url(); ?>/" method="get">
<fieldset>
if (get_locale() == "en_US") {
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search', 'alora'); ?>" />
</span>
}
else {
<span class="text"><input name="s" id="s" type="text" value="" placeholder="<?php echo __('Search_el', 'alora'); ?>" />
</span>
}
</fieldset>
</form>
But with no luck. Can anyone please help me?.
I also read this post Change text depending on language, but I couldn't figure it out.
<?php echo _e('Search_el', 'alora'); ?>" />
Please use this..
if above code not working than use..
printf(__('Search_el', 'alora'));
I have created a form to search posts in my blog, but my search returns posts from other blog (domain.com/) instead of (domain.com/myblog), yes is a multisite wordpress. i tried everything, follows my code:
<form class="navbar-form navbar-right searchform" role="search" method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="form-group">
<input name="s" id="s" type="text" class="form-control" placeholder="Search Programs" value="<?php echo get_search_query(); ?>">
</div>
<a id="searchsubmit" type="submit" class="btn"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></a>
</form>
you can resolve this problem by adding the following code in functions.php
function custom_pre_get_posts($query)
{
$parent_categories = ('myblog');
// you can search by slug or insert the category id directly. your choice
$cat_term_id = get_category_by_slug($parent_categories)->term_id;
if ($query->is_main_query() && !is_admin() && is_search())
$query->set('cat', $cat_term_id);
}
}
add_action('pre_get_posts', 'custom_pre_get_posts');
<form class="ms-global-search_form" method="get" action="<?php echo get_bloginfo('url').'/myblog/'; ?>">
<input id="s" class="field" name="mssearch" type="text" placeholder="Search across network sites:" size="16" tabindex="1" />
<input type="submit" id="searchsubmit" class="button submit" value="<?php _e( 'Search', 'ms-global-search' )?>" tabindex="2" />
</form>
ok i have a problem with the search i'm creating a new blog in wordpress and it's not working at all i tried a lot and nothing change
this is the header.php code
<div class="navbar-r">
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
<input class="in-s-n" type="text" name="s" <?php the_search_query();?> />
<input class="su-s-n" type="submit" value="Find" />
</form>
</div>
<!--End navbar-r-->
and when i search the page get blank
what do i have to do? any help
Try using something like:
<form role="search" method="get" id="searchform" class="searchform" action="<?php esc_url( home_url( '/' )); ?>">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
<input type="text" value="<?php get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
For more details, check out this link: http://codex.wordpress.org/Function_Reference/get_search_form
I am trying to create a theme and I am displaying a search box in the header using:
<?php get_search_form(); ?>
Is there a way that I can get placeholder text to show in that box?
I ended up figuring out that if I don't have a file called "searchform.php" in my theme folder, Wordpress displays is default form that doesn't include any placeholder text:
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<div><label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
I created a new file called "searchform.php" in my theme folder and modified the default form to include the placeholder text:
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<div>
<input type="text" value="" name="s" id="s" placeholder="Search gear, clothing, & more.." />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
make searchform.php in theme folder and place that code in it
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
<div>
<input class="text" type="text" value=" " name="s" id="s" />
<input type="submit" class="submit button" name="submit" value="<?php _e('Search');?>" />
</div>
</form>
Change whatever you want ! like class,placeholder,text any thing you want but not change like name, id and form attribute
Thanks
The WP codex has an example with a placeholder:
If your theme supports HTML5, which happens if it uses
add_theme_support('html5', array('search-form')), it will output the
following HTML form. This is the case since WordPress 3.6.
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<label>
<span class="screen-reader-text">Search for:</span>
<input type="search" class="search-field" placeholder="Search …" value="" name="s" title="Search for:" />
</label>
<input type="submit" class="search-submit" value="Search" />
</form>
If you don't want to use HTML5 tags and attributes, you can create placeholders with JavaScript.
The official get_search_form explained the more flexible modified that could add in your funtions.php.
check out here with CodeX commit.
TL;DR
Checkout the code below.
function wpdocs_my_search_form( $form ) {
// replace the new form on your own.
$form = '<form role="search" method="get" id="searchform" class="searchform" action="' . home_url( '/' ) . '" >
<div><label class="screen-reader-text" for="s">' . __( 'Search for:' ) . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'. esc_attr__( 'Search' ) .'" />
</div>
</form>';
return $form;
}
add_filter( 'get_search_form', 'wpdocs_my_search_form' );
I am using this code for my search:
<?php
function wp_search_form($form) {
$form = '<form method="get" id="searchform" action="' . get_option('home') . '/" >
'.wp_dropdown_categories('exclude=1 Categories&hide_empty=0&echo=0&selected='.intval($_GET['cat']).'').'
<input type="text" class="search_input" value="' . attribute_escape(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
<input type="submit" alt="Search" class="greybutton float_right" value="Search" />
</div>
</form>';
return $form;
}
I want to remove the catagory dropdown and instead make it search the current catagory
I don't want to steal TheDeadMedic's karma... my rating isn't high enough to comment on existing answers yet...
Here's his code put together:
function wp_search_form($form) {
global $wp_query;
$form = '<form method="get" id="searchform" action="' . get_option('home') . '/" >
<input type="hidden" name="cat" value="'. $wp_query->get_queried_object_id() .'" />
<input type="text" class="search_input" value="' . attribute_escape(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
<input type="submit" alt="Search" class="greybutton float_right" value="Search" />
</div>
</form>';
return $form;
}
Remove the wp_dropdown_categories() call and replace with;
<input type="hidden" name="cat" value="<?php echo $wp_query->get_queried_object_id(); ?>" />
Note if you're using that inside a function, you'll need to globalise $wp_query.
I make the search in current category with the following code (in searchform.php or where you want to put a search form:
<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<div>
<input type="text" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
<input type="hidden" name="cat" value="<?php echo $cat ;?>" />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>