How to display only second level child menu in wordpress

Below is snippet code to display second level menu in wordpress.
Put below php code into your theme/functions.php file

add_filter( 'wp_nav_menu_objects', 'my_wp_nav_menu_objects_sub_menu', 10, 2 );

// filter_hook function to react on sub_menu flag
function my_wp_nav_menu_objects_sub_menu( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$root_id = 0;
// find the current menu item
foreach ( $sorted_menu_items as $menu_item ) {
if ( $menu_item->current ) {
// set the root id based on whether the current menu item has a parent or not
$root_id = ( $menu_item->menu_item_parent ) ? $menu_item->menu_item_parent : $menu_item->ID;
break;
}
}
// find the top level parent
if ( ! isset( $args->direct_parent ) ) {
$prev_root_id = $root_id;
while ( $prev_root_id != 0 ) {
foreach ( $sorted_menu_items as $menu_item ) {
if ( $menu_item->ID == $prev_root_id ) {
$prev_root_id = $menu_item->menu_item_parent;
// don't set the root_id to 0 if we've reached the top of the menu
if ( $prev_root_id != 0 ) $root_id = $menu_item->menu_item_parent;
break;
}
}
}
}

$menu_item_parents = array();
foreach ( $sorted_menu_items as $key => $item ) {
// init menu_item_parents
if ( $item->ID == $root_id ) $menu_item_parents[] = $item->ID;

if ( in_array( $item->menu_item_parent, $menu_item_parents ) ) {
// part of sub-tree: keep!
$menu_item_parents[] = $item->ID;
} else if ( ! ( isset( $args->show_parent ) && in_array( $item->ID, $menu_item_parents ) ) ) {
// not part of sub-tree: away with it!
unset( $sorted_menu_items[$key] );
}
}
return $sorted_menu_items;
} else {
return $sorted_menu_items;
}
}

Then you can display it in your theme using wp_nav_menu (just like you normally would), but also passing in a sub_menu flag to activate the custom sub_menu function:

 'primary', /// Your primary theme location name as per theme code
'sub_menu' => true
) ); ?>

How to restrict user other than administrator to acess wp-admin in wordpress

Here is code restrict user other than administrator to acess wp-admin in wordpress.
Put below code into your theme/funtion.php file

function block_wp_admin_init() {

if (strpos(strtolower($_SERVER['REQUEST_URI']),'/wp-admin/') !== false) {
  if ( !is_site_admin() ) {
     wp_redirect( get_option('siteurl'), 302 );
  }
}
}
add_action('init','block_wp_admin_init',0);

How to reset user id in wordpress for new signup registration

Here is way to reset user id in wordpress for new signup registration.

  1. First Delete all your unwanted users from backend.
  2. Now go to phpmyadmin to acess you database.
  3. Click on SQL tab from top and Enter below SQL COMMAND and Click GO button.
  4. ALTER TABLE wp_users AUTO_INCREMENT = 15

That’s it.

How to manage wordpress comments using php mysql

Here is way to manage your wordpress comments using php mysql queries.

Some things to note

  • Don’t forget to do a backup of your database before testing any of the queries below.
  • Don’t forget to change the default table prefix wp_ by the one used by your database.

Delete all spam comments

When you have over 100,000 spam comments in your spam queue, deleting them using the built-in “delete all spam” button might result in a PHP memory error. To avoid this, just use this simple SQL request to delete all spam at once.

DELETE from wp_comments WHERE comment_approved = 'spam'

Delete all comments between two dates

Had a “spam attack” for a limited time? Here is an easy way to delete all comments between two dates.

DELETE FROM wp_comments 
WHERE comment_date > '2013-11-15 01:10:04'
AND comment_date <= '2013-11-20 00:10:04'

Delete all pending comments

If your “pending comment” queue is filled with 99% spam comments and you don’t want to manually review each of them, here is a SQL command to instantly erase all pending comments.

DELETE FROM wp_comments WHERE comment_approved = '0'

Disable comments on all posts at once

Want to disable comments on all of your posts? Instead of closing comments on all your posts the one after the other, why not using this super simple SQL query?

UPDATE wp_posts SET comment_status = 'closed', ping_status = 'closed' WHERE comment_status = 'open'

Disable comments on older posts

To limit spam, why not closing comments on older posts? Here is the SQL to automatically close comments on all posts older than January 1, 2014:

UPDATE wp_posts SET comment_status = 'closed' WHERE post_date < '2014-01-01' AND post_status = 'publish'

Source: http://perishablepress.com/wordpress-discussion-management…

delete comments with a specific url

Even if you’re careful when approving new comments, sometimes you might just forget to visit the commenter url and detect a long time after that the linked site is spammy. Here is a very easy way to bulk delete all comments with a specific url, using a simple SQL query.

DELETE from wp_comments WHERE comment_author_url LIKE "%nastyspamurl%" ;

Source: http://www.wprecipes.com/wordpress-tip-bulk-delete-comments…

Search and replace comment text

If there’s a specific word or sentence that you want to replace in all comments, here is a very handy SQL query which use the mysql REPLACE function.

UPDATE wp_comments SET `comment_content` = REPLACE (`comment_content`, 'OriginalText', 'ReplacedText')

Globally enable comments for registered users only

A very effective way to dramatically decrease the amount of received spam comment is to enable comments for registered users only. Instead of doing it on each post, here’s a SQL query to run in oder to do it on all posts at once.

UPDATE wp_posts SET comment_status = 'registered_only'

Source: http://digwp.com/2010/08/wordpress-sql-comments/

How to change/ overwrite wordpress backend footer message

Here is code for change/ overwrite wordpress backend thankyou message. Put this code into your current theme function.php file

// Custom WordPress Footer
function remove_footer_admin () {
	echo '&copy; 2012 - WordPress Channel, Aur&eacute;lien Denis';
}
add_filter('admin_footer_text', 'remove_footer_admin');

How to change wordpress backend login logo

Here is code to change wordpress backend login logo. Put this code into your current theme function.php file.

function custom_login_logo() {
	echo '<style type="text/css">
	h1 a { background-image: url(http://webdesignermumbai.net/work/shivam/wp-content/themes/akhil/images/akhil-bharatvarshiya-logo.png) !important;width:397px !important;height:75px !important;background-size:397px 75px !important; }
	#login {width:400px !important}
	</style>';
}
add_action('login_head', 'custom_login_logo');

How to disable wordpress update notification

here is code to disable wordpress backend update notification. put this into your current theme function.php file

add_action('admin_menu','wphidenag');
function wphidenag() {
remove_action( 'admin_notices', 'update_nag', 3 );
}

How to add own style css into wp-admin backend using theme function hook

Here is snippet to add own style css into wp-admin backend using theme function hook.

function my_custom_admin_head(){
echo '<style>.yourclass {display: none !important;}</style>';
}
add_action('admin_head', 'my_custom_admin_head');

How to remove empty lines using regular expression in notpad++

I hope this tips will help you as wed designer to reduce files size by removing empty lines from file using notepadd++

Just Write “^s*” in Find Text box and replace with blank.

Server side responsive with cookies

here is code which i done after searching over google with help of different website.

<script type="text/javascript">
		function setCookie(cname,cvalue,exdays)	{
			var d = new Date();
			d.setTime(d.getTime()+(exdays*24*60*60*1000));
			var expires = "expires="+d.toGMTString();
			document.cookie = cname+"="+cvalue+"; "+expires;
		}
		windowwidth = document.body.clientWidth;
		setCookie("wwidth",windowwidth,30);
		var user1=getCookie("wwidth");
		//alert('user1'+user1);
		</script>
		<?php $screenWidth = $_COOKIE['wwidth'] ?>

Condition php code

<?php if ($screenWidth <= 660) { ?>
		<div class="class1" id="content">
	<?php } else { ?>
		<div class="class2" id="content">
	<?php } ?>

How Separate First post from Other in wordpress loop

As wordpress freelancer i found way to first post from Other in wordpress loop. Below is php code for same.

$latest_post = new WP_Query("post_type=post&posts_per_page=5&orderby=date&order=DESC");
if ( $latest_post->have_posts() ) :  $i = 0; while ( $latest_post->have_posts() ) : $latest_post->the_post();
if ( $i == 0 ) { ?>
<!-- FIRST POST CODE WILL COME HERE -->
<?php }else{ ?>
<!-- Others POST CODE WILL COME HERE -->
<?php }  
$i++;  
endwhile;  
endif; 

jQuery Get every third/ specific level of element

Here is jquery code to third/ specific level of element

jQuery('#portfolioItem li:nth-child(3n+3)').css({ marginRight: '0px' });

How to get bbpress Topic author id and current user id

Here is code which will show you wordpress bbpress topic author ID and wordpress current user id.

<?php 
$author_id = get_the_author_meta('ID') ;
$currentuserID = bbp_get_current_user_id();
echo 'Author ID '. $author_id .'';
echo 'Current User Id' .$currentuserID.'';
 ?>

How to Create wordpresss breadcrumb without plugin

Here is code to show how you can create wordpress breadcrumb feature without installing any plugin.

Open your functions.php and paste the code below in it:

function the_breadcrumb() {
                echo '<ul id="crumbs">';
        if (!is_home()) {
                echo '<li><a href="';
                echo get_option('home');
                echo '">';
                echo 'Home';
                echo "</a></li>";
                if (is_category() || is_single()) {
                        echo '<li>';
                        the_category(' </li><li> ');
                        if (is_single()) {
                                echo "</li><li>";
                                the_title();
                                echo '</li>';
                        }
                } elseif (is_page()) {
                        echo '<li>';
                        echo the_title();
                        echo '</li>';
                }
        }
        elseif (is_tag()) {single_tag_title();}
        elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
        elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
        elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
        elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
        elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
        elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
        echo '</ul>';
}

Once done, open header.php and call the function:

<?php the_breadcrumb(); ?>

How to add Custom field in custom portfolio type post

Here is solution to add custom field in your custom portfolio entries, for this you must activate the “custom fields” manually.
Open up portfolio.php OR php function where you registering post type “portfolio. portfolio_register() and search for:

'supports' => array('title','thumbnail','excerpt','editor','comments')

Replace it with

'supports' => array('title','thumbnail','excerpt','editor','comments','custom-fields')

How to check post or page has an attachment in wordpress

Here is code to check post or page has an attachment in wordpress. You have to in wordpress loop.

<?php
if ( is_attachment() ) {
	echo 'Has an Attachment';
} else {
	echo 'Not has an Attachment';
}
?>
Page 1 of 1212345...10...»

Wordpress Freelancer, Joomla Freelancer Web designer Mumbai india, Wordpress web developer India, Joomla Web developer india, Outsourcing web project india mumbai

By Santosh Kori Published: October 10, 2012 Professional Freelance Website developer 5 stars based on 65 reviews Total time: 24 hour 00 min Wordpress Joomla XHTML CSS jQuery HTML5 eCommerce CSS3 ☞ Offers low cost freelance web designing, asp php asp.net web development services from Mumbai India. Freelance web designer & developer Mumbai India.