Using <!--more--> tag to output text in Genesis?

here's what i'm trying to achieve!

HTML:

some text
!--more--
some text

when post is loaded:

some text
MY TEXT WHICH WAS ADDED TO THE MORE TAG
some text

on my old WP site, i used this to have a banner displayed on posts exactly where the tag was inserted.

unfortunately, i can't get this to work in Genesis.

here's the code which was added to functions.php on my old website:

function adsense_added_at_more_tag($text) {
if( is_single() ) :
$ads_text = 'BANNER GOES HERE';
$pos1 = strpos($text, 'span id="more-');
$pos2 = strpos($text, '/span', $pos1);
$text1 = substr($text, 0, $pos2);
$text2 = substr($text, $pos2);
$text = $text1 . $ads_text . $text2;
endif;
return $text;
}

any ideas on how to get this to work in Genesis?

i got some great tips from Brad who suggested the following code:

add_filter( 'the_content_more_link', 'read_more_link' );
function read_more_link() {
if ( is_single() ) {
echo 'div class="your-banner"Add Your Banner HTML Here/div';
    }
}

i've tried adding this to functions.php in Genesis, but nothing happens. the "Add Your Banner HTML Here" text doesn't appear in the post.

i've explored various code examples online and tried tweaking the code pasted above with my (it's safe to say) non-existant PHP skills without success.

can anyone figure out how to modify the code to show text in a single post in Genesis?

Topic functions adsense read-more tags php Wordpress

Category Web


ok, here's the solution:

Text after more tag in posts

tested and working in Genesis!


You can hook in the banner using the the_content_more_link filter by modifying this code.

add_filter( 'the_content_more_link', 'sp_read_more_link' );
function sp_read_more_link() {
return '<a class="your-banner" href="' . get_permalink() . '">[Banner Shortcode]</a>';
}

Another option would be to create a shortcode for your banner, and add the shortcode to the the_content_more_link filter above.

Or you could simply echo the div class and/or HTML for the banner in a custom function with or without a conditional tag.

add_filter( 'the_content_more_link', 'read_more_link' );
function read_more_link() {
if ( is_single() ) {
echo '<div class="your-banner">Add Your Banner HTML Here</div>';
    }
}

Either add HTML for your banner or create a shortcode otherwise the code does nothing.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.