Instead of trim words how to add custom excerpt in wordpress

 First go to blog posts and edit one.

Now you will not see here any input to type custom excerpt for this post.

In Post menu in right sidebar you will see add excerpt in top.

Add dummy excerpt in this post and update.

Now go to front-page.php and find blog section where we added 18 words trim function. lets modify here

Now change that code with below

<?php if(has_excerpt()) {
              echo get_the_excerpt();
          }else {
            echo wp_trim_words(get_the_content(), 18);
          } ?>

and save that.

Now add this feature in event posts

go to any event and edit one and add excerpt.

With edit event post you will not see excerpt option and also there is classic editor.

Means we have to tell wordpress to support excerpt feature by code.

So go to mu-plugins folder and open custom post type code for event.

so add this line in custom post type function

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

and save.

and also if you want modern editor not classic so update custom post type function with below line

'show_in_rest' => true,

and save.

and for event post in front-page.php display excerpt use above code like post.

and also add below code for view all events

<p class="t-center no-margin"><a href="<?php echo get_post_type_archive_link('event');  ?>"
          class="btn btn--blue">View
          All
          Events</a></p>

Update menu link for event like below
 <li <?php if(get_post_type() == 'event') echo 'class="current-menu-item"'; ?>><a
                href="<?php echo get_post_type_archive_link('event');  ?>">Events</a></li>

Comments

Popular posts from this blog

Basics Of PHP

Creating App.js for Node Application

WordPress Full Guide For Developer