how to show post excerpt wordpress

How to show post excerpt in wordpress?

There are two ways to show post excerpt in WordPress. I will show you here.

First method:

First add this code in functions.php


function new_excerpt_more( $more ) {
return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'your-text-domain') . '</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );

then add this code in the loop and single.php

the_excerpt();

You can show featured images too, just add the_post_thumbnail();

Another Method:

First add these codes in functions.php just like first methods.

function get_excerpt($count){
$permalink = get_permalink($post->ID);
$excerpt = get_the_content();
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
return $excerpt;
}

Then add get_excerpt(125); in your themes loop and single.php

Done !

How to add secondary menu in footer

By default, every theme has a primary menu. Suppose, you need to add an extra menu. Yes, you can. WordPress has a function called register_nav_menu that will let you create an extra menu anywhere in the site as you wish. The wp_nav_menu function will display the menu in the desired place.

This is how to add secondary menu in footer

First, we need to register secondary menu. To do that we have to add this code in functions.php

register_nav_menu('secondary', __('Secondary Menu', 'framework'));

Then add this code in footer.php or wherever you want to show the menu.

'secondary', 'menu_class' => 'sf-menu', 'container' => '' ) ); ?>

After adding those codes, you will see an extra menu in Dashboard > Appearance > Menus. Then add links there as same as primary menu.

But keep in mind, for styling the menu, use your own CSS or use mine.

/*add this code in your primary menu in functions.php. the code will look like*/

register_nav_menus( array(
		'secondary' => esc_html__( 'Secondary Menu', 'underbootup' ),
	) );


/*add this code in footer.php or where you want to show. you can change the CSS class or ID as per your stylesheet*/

<div class="main-menu-wrapper-footer">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <nav class="navigation1">
              <?php wp_nav_menu( array( 'theme_location' => 'secondary', 'menu_class' => 'sf-menu', 'container' => '' ) ); ?>       
            </nav>
          </div>
        </div>
      </div>
    </div>
    
    /*the CSS i've used*/
    
    .navigation1{
	height:50px;
	text-align:center;
}
.navigation1 > ul{
	margin:0;
	list-style-type:none;
}
.navigation1 > ul > li{
	float:left;
	font-size:15px;
	position:relative; left:25%;
}
.navigation1 > ul > li i{
	font-size:11px;
	margin-left:5px; 
}
.navigation1 > ul > li > a{
	padding:15px 22px;
	display:block;
	text-decoration:none;
	border-right:1px solid rgba(0,0,0,.05); color:#fff;
}
.navigation1 > ul > li:first-child > a{
	border-left:1px solid rgba(0,0,0,.05);
}
.navigation1 ul > li:hover > a, .navigation1 ul > li.current_menu_item > a{
	border-top-width:3px;
	border-top-style:solid;
	padding:12px 22px 15px 22px;
	background:#fff; color:#000;
}
.navigation1 > ul > li ul{
	position:absolute;
	margin:0;
	list-style-type:none;
	top:100%;
	left:0;
	z-index:999;
	display:none;
	min-width:100%;
	height:auto;
	background:#fff;
	text-align:left;
	box-shadow:0 2px 2px rgba(0,0,0,.3);
}
.navigation1 > ul > li:hover ul{
	display:block;
}
.navigation1 > ul > li > ul li{
	line-height: normal;
	font-size:14px;
	position:relative;
}
.navigation1 > ul > li > ul li > a{
	display:block;
	padding:10px 25px;
	border-bottom:1px solid #f8f7f3;
	white-space:nowrap;
	text-decoration:none; 
}
.navigation1 > ul > li > ul > li:hover > a, .navigation1 > ul > li > ul > li > ul > li:hover > a{
	text-decoration:none;
	padding:10px 25px;
	color:#fff;
	border-top:0;
}
.navigation1 > ul > li > ul li:last-child a{
	border-bottom:0;
}
.navigation1 > ul > li > ul li ul{
	margin:0;
	list-style-type:none;
	left:100%!important;
	top:0;
	min-width: inherit;
	position:absolute;
	box-shadow:0 2px 2px rgba(0,0,0,.3);
}

All codes together in gist.

Done!

See the example

How to add secondary menu in footer

customize footer in Genesis Framework

How to customize footer in Genesis Framework

customize footer in Genesis Framework
If you need to customize footer in genesis framework manually, then follow these snippets. Just add one of the codes snippets in functions.php you are done.

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Customize the credits
add_filter( 'genesis_footer_creds_text', 'sp_footer_creds_text' );
function sp_footer_creds_text() {
	echo '<div class="creds"><p>';
	echo 'Copyright &copy; ';
	echo date('Y');
	echo ' &middot; <a href="http://mydomain.com">My Custom Link</a> &middot; Built on the <a href="http://www.studiopress.com/themes/genesis" title="Genesis Framework">Genesis Framework</a>';
	echo '</p></div>';
}
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Change the footer text
add_filter('genesis_footer_creds_text', 'sp_footer_creds_filter');
function sp_footer_creds_filter( $creds ) {
	$creds = '[footer_copyright] &middot; <a href="http://mydomain.com">My Custom Link</a> &middot; Built on the <a href="http://www.studiopress.com/themes/genesis" title="Genesis Framework">Genesis Framework</a>';
	return $creds;
}

The codes source is here.

Although you can use this plugins called “Genesis Simple Edits” to edit/change the footer texts.

extra stock option in woocommerce

Adding extra stock option in Woocommerce

extra stock option in woocommerce

extra stock option in woocommerce

When you need to add an extra stock option in woocommerce i.e. “request to buy” “on request available” etc.  then simply you need to make a tweak. just add this code in functions.php you are done. simple!

/*adding stock option*/

function add_custom_stock_type() {
    ?>
    <script type="text/javascript">
    jQuery(function(){
        jQuery('._stock_status_field').not('.custom-stock-status').remove();
    });
    </script>
    <?php   
    woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
        'instock' => __( 'In stock', 'woocommerce' ),
        'outofstock' => __( 'Out of stock', 'woocommerce' ),
        'onrequest' => __( 'Available to Order', 'woocommerce' ), // The new option !!!
    ), 'desc_tip' => true, 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ) ) );
}
add_action('woocommerce_product_options_stock_status', 'add_custom_stock_type');

function save_custom_stock_status( $product_id ) {
    update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
}
add_action('woocommerce_process_product_meta', 'save_custom_stock_status',99,1);

function woocommerce_get_custom_availability( $data, $product ) {
    switch( $product->stock_status ) {
        case 'instock':
            $data = array( 'availability' => __( 'In stock', 'woocommerce' ), 'class' => 'in-stock' );
        break;
        case 'outofstock':
            $data = array( 'availability' => __( 'Out of stock', 'woocommerce' ), 'class' => 'out-of-stock' );
        break;
        case 'onrequest':
            $data = array( 'availability' => __( 'Available to Order', 'woocommerce' ), 'class' => 'on-request' );
        break;
    }
    return $data;
}
add_action('woocommerce_get_availability', 'woocommerce_get_custom_availability', 10, 2);

Please note: It only works on simple products, not on variable products.

Update: this code is not working with latest Woocommerce. Please use this plugin.