Site logo

Archived topic

Remove words Read More when post length exceeds limit

13 replies · Started by Steig on April 26, 2019

Viewing posts 1–14 of 14

Hello,

On the post archive page, which is my home page, I have the content type set to excerpt with 20 word count.

When the words exceed this figure, three dots and then the words Read more are appended.

Can the hyperlink for "read more" be removed?

In fact, what I'd like is for the entire post excerpt to be clickable. Right now just the post title is. That is done through PHP in the content.php file

<?php
/**
 * The template for displaying posts within the loop.
 *
 * @package GeneratePress
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php generate_do_microdata( 'article' ); ?>>
	<div class="inside-article">
		<?php
		/**
		 * generate_before_content hook.
		 *
		 * @since 0.1
		 *
		 * @hooked generate_featured_page_header_inside_single - 10
		 */
		do_action( 'generate_before_content' );
		?>

		<header class="entry-header">
			<?php
			/**
			 * generate_before_entry_title hook.
			 *
			 * @since 0.1
			 */
			do_action( 'generate_before_entry_title' );

			the_title( sprintf( '<h2 class="entry-title" itemprop="headline"><a class="sg-iframe-popup-133" href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );

			/**
			 * generate_after_entry_title hook.
			 *
			 * @since 0.1
			 *
			 * @hooked generate_post_meta - 10
			 */
			do_action( 'generate_after_entry_title' );
			?>
		</header><!-- .entry-header -->

		<?php
		/**
		 * generate_after_entry_header hook.
		 *
		 * @since 0.1
		 *
		 * @hooked generate_post_image - 10
		 */
		do_action( 'generate_after_entry_header' );

		if ( generate_show_excerpt() ) : ?>

			<div class="entry-summary" itemprop="text">
				<?php the_excerpt(); ?>
			</div><!-- .entry-summary -->

		<?php else : ?>

			<div class="entry-content" itemprop="text">
				<?php
				the_content();

				wp_link_pages( array(
					'before' => '<div class="page-links">' . __( 'Pages:', 'generatepress' ),
					'after'  => '</div>',
				) );
				?>
			</div><!-- .entry-content -->

		<?php endif;

		/**
		 * generate_after_entry_content hook.
		 *
		 * @since 0.1
		 *
		 * @hooked generate_footer_meta - 10
		 */
		do_action( 'generate_after_entry_content' );

		/**
		 * generate_after_content hook.
		 *
		 * @since 0.1
		 */
		do_action( 'generate_after_content' );
		?>
	</div><!-- .inside-article -->
</article><!-- #post-## -->

Could you tell me how to make the entire excerpt clickable so I can trigger this popup?

Thanks

I've edited the footer.php file as follows. I get an error message on line 44, which is the row where <script> is

<?php
/**
 * The template for displaying the footer.
 *
 * @package GeneratePress
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
?>

	</div><!-- #content -->
</div><!-- #page -->

<?php
/**
 * generate_before_footer hook.
 *
 * @since 0.1
 */
do_action( 'generate_before_footer' );
?>

<div <?php generate_do_element_classes( 'footer' ); ?>>
	<?php
	/**
	 * generate_before_footer_content hook.
	 *
	 * @since 0.1
	 */
	do_action( 'generate_before_footer_content' );

	/**
	 * generate_footer hook.
	 *
	 * @since 1.3.42
	 *
	 * @hooked generate_construct_footer_widgets - 5
	 * @hooked generate_construct_footer - 10
	 */
	do_action( 'generate_footer' );

<script>
jQuery( document ).ready( function($) {
    var body = $( 'body' );
    if ( body.hasClass( 'blog' ) || body.hasClass( 'archive' ) ) {
        $( '.type-post' ).on( 'click', function() {
            var link = $( this ).find( '.entry-title a' ).attr( 'href' );
            if ( link ) {
                window.location = link;
            }
        } );
    }
} );
</script>

	/**
	 * generate_after_footer_content hook.
	 *
	 * @since 0.1
	 */
	do_action( 'generate_after_footer_content' );
	?>
</div><!-- .site-footer -->

<?php
/**
 * generate_after_footer hook.
 *
 * @since 2.1
 */
do_action( 'generate_after_footer' );

wp_footer();
?>

</body>
</html>

My goal has been to make the entire excerpt clickable so it launches a pop up.

I had placed a call in the content.php file that did that for the post title only:

<header class="entry-header">
			<?php
			/**
			 * generate_before_entry_title hook.
			 *
			 * @since 0.1
			 */
			do_action( 'generate_before_entry_title' );

			the_title( sprintf( '<h2 class="entry-title" itemprop="headline"><a class="sg-iframe-popup-133" href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );

			/**
			 * generate_after_entry_title hook.
			 *
			 * @since 0.1
			 *
			 * @hooked generate_post_meta - 10
			 */
			do_action( 'generate_after_entry_title' );
			?>
		</header>

the relevant call is <a class="sg-iframe-popup-133" href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a>

Could that be inserted into this wp-footer hook somehow to make the entire excerpt call this popup?

It depends on how the popup is initiated. If it's initiated via javascript, it might be possible to initiate it when clicking the entire area instead of the sg-iframe-popup-133 element. However, you'd need to bring this up with the popup plugin developer to know for sure.

One thing I've noticed is that while the post excerpt does appear to be a single clickable area now, clicking it doesn't do anything. I would assume it would at least take the view to the post detail page.

I removed the content.php code that caused a click to the post title to launch the popup just to see if that was causing a conflict and now a click to the post title simply now moves to the detailed post page.

How can clicking the entire excerpt container produce the same behavior?

I do have that added into the Simple CSS window:

/* excerpt container is clickable with wp footer javascript */
.blog .type-post, 
.archive .type-post {
    cursor: pointer;
}

When I mouse over the blog excerpt, I do have a the hand pointer cursor, but it doesn't click to anywhere, except on the title only.

You need the other part of the code as well:

1. Create a Hook Element: https://docs.generatepress.com/article/hooks-element-overview/
2. Set the hook to wp_footer
3. Add this code as the content:

<script>
jQuery( document ).ready( function($) {
    var body = $( 'body' );
    if ( body.hasClass( 'blog' ) || body.hasClass( 'archive' ) ) {
        $( '.type-post' ).on( 'click', function() {
            var link = $( this ).find( '.entry-title a' ).attr( 'href' );
            if ( link ) {
                window.location = link;
            }
        } );
    }
} );
</script>

Then set the Display Rules.

I do have that Hook element created, but realized I didn't have a display rule set. I tried post archive and also just post and neither caused the desired effect.

Try setting your display rule to Front Page

super; thank you!

Glad we could be of help.

This archived topic is closed to new replies.