Archived topic
Custom Intro for Each Category Archive for First Page Only
22 replies · Started by surfing on March 21, 2018
Hi there,
the simplest method would be to hide the element with some CSS eg.
body[class^="category-paged-"] .hero-description {
display: none;
}
Then wrap your description content within a HTML Element that has the class to hidden:
<p class="hero-description">The description</p>
Please stop downloading code and then hiding it with css.
Unless there is a fundamental SEO issue i don't see what the problem is here, as we're only dealing with text that only requires a simple database query.
But there are alternatives, one of which is to create a shortcode to output the description and only output it on non paged archives eg.
add_shortcode( 'term_description', 'tu_term_description' );
function tu_term_description() {
if (!is_paged()) {
ob_start();
echo term_description( get_queried_object()->term_id, 'category' );
return ob_get_clean();
}
}
Which will provide you with this shortcode [term_description]
OK so here is a simple Element Header:
<h1>{{post_title}}</h1>
<p>{{custom_field.description}}</p>
<p>
Subscribe Now
</p>
I can change this to
<h1>{{post_title}}</h1>
<p>[show_excerpt]</p>
<p>
Subscribe Now
</p>
and write a shortcode that returns the excerpt on the first page and otherwise return empty
Something like this:
add_shortcode( 'show_excerpt', function() {
ob_start();
if( is_archive() && !is_paged() ) {
echo get_the_excerpt();
}
return ob_get_clean();
} );
But this shortcode needs work!
OK yes, that worked. Very easy! Thank You!!!
Yeah I got it thanks.
You're welcome