Saturday, November 21, 2020

WP - post content image - keep aspect ratio

 class="wp-block-image "


.wp-block-image img{

max-width: 100%;

    height: auto;

}



or


.myclass  img{

max-width: 100%;

    height: auto;

}

WP Featured Image and Post Thumbnail

 


add in functions.php


add_theme_support( 'post-thumbnails' );

add_image_size('small-thumbnail', 350, 230, true);

add_image_size('post-image', 600, 400, true);



single.php

                  <?php the_post_thumbnail('post-image'); ?>




Monday, November 16, 2020

Wordpress Page contents display with if page id condition

Display some contents in certain pages of wordpress only.

Hide contents from some pages.


<?php  if(is_page(14))  {?>


display this.....

<?php  }   ?>

Sunday, November 15, 2020

Wordpress Post page designing with code

 Create file


single.php


Referance: https://wordpress.org/support/topic/create-new-basic-single-php-template/


<?php while ( have_posts() ) : the_post(); ?>



POST TITLE

<h1 class="intro-title mb-4"><h1 class="page-title"><a href="

<?php the_permalink(); ?>"><?php the_title();?>

</a></h1>



POST CONTENT

    <p>

        <?php the_content(); ?>

    </p>


<?php endwhile; ?>




Wednesday, November 11, 2020

Wp menu code - Navigation menu

 Activating navigation menu and using it with code.

function.php


add_theme_support('menus');

register_nav_menus(
    array(

        'primary-menu' => 'Primary Menu',
    )
)


<?php   echo get_home_url();  ?>


index.php

<?php 

$defaults = array( 

'container' => 'ul',

'theme_location' =>   'primary-menu',

'menu_class'  => 'nav navbar-nav '

);

wp_nav_menu( $defaults); 

?>



or


    $defaults = array
     'container' => 'ul',
     'theme_location' =>   'primary-menu',
     'menu_class'  => 'navbar-nav'
     );

     wp_nav_menu$defaults); 



Wordpress Home URL Button -- Php code

Home Button in Navigation menu of wordpress

 <li class="nav-item">
            <a class="nav-link js-scroll" 
                href="<?php   echo get_home_url();  ?>">Home</a>
 </li>

Wordpress page template -- landing page

 create new file


landing.php



<?php

/*
Template Name: Landing
*/
get_header(); 

?>