How to add permalink into WP_Query in WordPress Theme

I want to add Blog Page in front-page.php.I want to show only post title with link to actual post.I dont know where to put the_permalink in my code.My code like below:

 <div class="profile">               
                <?php 
                  $query = new WP_query( 'pagename=blog' ); 
                    if ( $query->have_posts() ) {
                    while ( $query->have_posts() ){
                    $query->the_post();
                    echo '<h2 class="text-center">' . get_the_title() . '</h2>';                                
                       }
                     }
                  wp_reset_postdata();
                 ?>   
 </div><!--end blog-content -->     

When I put ,the hyperlink goes to domain.com/get_permalink() not to actual url.

Read More

Example the actual url is domain.com/abc.
When I click to the post title,it goes to domain.com/get_permalink()

Anyone can help me to solve my problem?

Related posts

Leave a Reply

1 comment

  1. May be you are using get_permalink in wrong way. Try following code.

    <div class="profile">
      <?php
      $query = new WP_query( 'pagename=blog' );
      if ( $query->have_posts() ) {
        while ( $query->have_posts() ){
          $query->the_post();
          echo '<h2 class="text-center"><a href="' . get_permalink() . '">';
          the_title();
          echo '</a></h2>';
        }
      }
      wp_reset_postdata();
      ?>
    </div><!--end blog-content -->