Add text to the label element search bar Wordpress - php

I want to display a search bar in the Wordpress navigation menu, for this I added this in my functions.php file:
add_filter('wp_nav_menu_items', 'sydney_child_add_serch_from_to_nav', 10, 2);
function sydney_child_add_serch_from_to_nav($items, $args){
if ($args->theme_location == 'primary') {
$items .= '<li class="top-search-menu">'.get_search_form(false).'</li>';
}
return $items;
}
The problem being that my sites must be valid WCAG 2.0 (Level A), but I have the following error:
I tried several solutions to add a label but without success. I have the same error when using a search plugins.
Thank you in advance.

Related

Adding a dynamic logo to Genesis primary nav

I would like to add a logo ( get_custom_logo() ) in the Genesis navigation bar but when it's blank, there's to be text. I've achieved this in a similar fashion for the header but cannot for the primary nav. The end result DOES work but when the user goes to the "customize" part of "site identity" the change is not visible, until you hit "publish" then refresh the actual page.
I need the change to be seen in "customize" mode as the logo is being changed. Here's the code the semi-functions...
add_filter( 'wp_nav_menu_items', 'prefix_add_menu_item', 10, 2 );
/**
* Add Menu Item to end of menu
*/
function prefix_add_menu_item ( $items, $args ) {
if( $args->theme_location == 'primary' ) {
if (( has_custom_logo())) {
$thelogo = get_custom_logo();
$items .= '<li class="menu-item">' . $thelogo . '</li>';
} else {
$items .= '<li class="menu-item">Theme Name</li>';
return $items;
}
return $items;
}
}
Ideally, I'd like to apply this method throughout the site for other hooks. If anyone can point to what I'm doing wrong, that would help.
Cheers.
It won't refresh in preview unless you add a custom setting to $wp_customize for your image or you add a new PHP class for the site logo. Either way, it's not an easy fix.

How to replace My Account and add login/logout links to menu in Woocommerce?

I am using woocommerce and I add the one menu My Account using woocommerce plugin But I want to show the menu login and logout instead of My Account which I add the into menu. I also added the script into functions.php result is same.
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary_navigation') {
//echo "hello friend how are";
$items .= '<li>Log Out</li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary_navigation') {
$items .= '<li>Log In</li>';
}
return $items;
}
When I am using jupitor theme and when I see the theme location of My Account Menu I get
Primary Navigation
I have a one doubt is I have to add the My Account menu first then I add the login and logout menu.
Your above code will add login/logout links to menu. You do not have to add My Account menu.
Please check your theme_location. If theme location is correct then login/logout link will add to menu.
For check theme_location you have to search register_nav_menus in functions.php file of your theme. If you find it in functions.php file then you can see theme_location inside register_nav_menus code.

wordpress: set class of navigation element to content of element

i'm new to wordpress theming and I currently try to implement a navigation menu using icons. The framework i use requires me to set specific class names to achieve the icon being displayed - so what i basically want is:
<ul>
<li class="blog">blog</li>
....
So the class should be equal to the content
I found the following in the wordpress docs
add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
function special_nav_class($classes, $item){
if(is_single() && $item->title == "Blog"){
$classes[] = "special-class";
}
return $classes;
}
This is how I currently display my menu
wp_nav_menu( array( 'theme_location' => 'primary', 'menu_id' => 'primary-menu' ) );
I'm kind of confused by the example given from the wordpress doc's since I cannot figure out the use of al the parameters or even where to place it.
I assume that you are registered your primary menu in functions.php.
After that you must put this code sample again in your functions.php.
What the code does is that it would launch the function special_nav_class for each menu item from primary-menu. As a parameter this function will receive the current menu item ( as post object ) and current classes applied for it as an array.
So, if you have menu with 5 elements, this function will run 5 times and each time it will receive current menu item and its classes array.
Basically something like this can do the job, if menu items are named properly:
function special_nav_class($classes, $item){
$classes[] = strtolower($item->title);
return $classes;
}

Adding dynamic Link to menu Item in wordpress

I want to have 'Text only' in menu of my wordpress website without plugin.So how to set dynamic link to menu item in wordpress?
try this one
add_filter('wp_nav_menu_items', 'menu_link', 10, 2);
function menu_link($items, $args) {
if ($args->menu == 'footer'){
$items .= '<li class="copyright ">Text Only</li>';
$items .= '<li class="copyright ">Print Page</li>';
}
return $items;
// return $items1;
}
You will have to recreate the complete menu walker to make it text only, or remove the anchor through jquery. But if you just want a menu item that doesn't link anywhere, create a normal link menu item, and instead of an actual link use #.

How to remove Text area of comment in Wordpress?

Hellow there all I tried searching everywhere but I coudn't just find it - may be because its a wiered requirement all I want to do is remove my Comment Text area in wordpress comment - I sucessfully removed URL website and name in the comment field by using following code
<?php
function remove_comment_fields($fields) {
unset($fields['url']);
unset($fields['author']);
unset($fields['email']);
return $fields;
}
add_filter('comment_form_default_fields','remove_comment_fields');
?>
But not able to remove the Text area - Actually you all will thought what will I do removing all this I am using a plugin which allow you to post images in your comment and the only option I want to give to user is post images via comment. please guide me.
Two options, the comment_form_defaults filter:
add_filter( 'comment_form_defaults', 'so16856397_comment_form_defaults', 10, 1 );
function so16856397_comment_form_defaults( $defaults )
{
$defaults['comment_field'] = '';
return $defaults;
}
or the comment_form_field_comment filter:
add_filter( 'comment_form_field_comment', 'so16856397_comment_form_field_comment', 10, 1 );
function so16856397_comment_form_field_comment( $field )
{
return '';
}
Check the comment_form source code.
You can also hide the textarea comment box by taking its id set to display:none from CSS
Just simple, add this code in functions.php file
function disable_comments_everywhere( $open, $post_id ) {
return false;
}
add_filter( 'comments_open', 'disable_comments_everywhere', 10 , 2 );

Categories