eZ_Harry
eZ_Harry

Reputation: 826

Wordpress make entire blog post clickable

Currently my blog posts have a small "view more" link at the bottom. Ideally, I would like to change it so that you can click anywhere in the <article class="blog-post"> and it will link you to the relevant article.

I have figured out how to do it so the excerpt is clickable, but cannot convert it to for the entire article

Code for the excerpt -

function clickable_excerpt( $post ) {
    return '<a href="'. get_the_permalink() .'" class="post">'. $post .'</a>';
}
add_filter( 'get_blog_post', 'clickable_excerpt' );

Upvotes: 1

Views: 1185

Answers (2)

Ravi Joon
Ravi Joon

Reputation: 44

Find class="grid-item" in your theme code, i found it at content.php and then add onclick javascript on article tag, like below

<article id="post-<?php the_ID(); ?>" <?php post_class('grid-item'); ?> onclick="document.location='<?php the_permalink(); ?>'">

also don't forgot to add CSS

article.grid-item {cursor: pointer;}

Upvotes: 2

red
red

Reputation: 1629

Try this:


 add_filter( 'the_content', 'filter_content' ); 

 function filter_content( $content ) { 
    if ( is_singular('post') ) {

        $content = <a href="'. get_the_permalink() .'" class="post">'. $content .'</a>;

        }

    return $content;
}

Better if you can do it directly in your theme single page template, this link help you to identificate the correct page in your theme: https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post

Upvotes: 0

Related Questions