WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Clear all after the more tag on single articles (13 posts)

  1. Jeremy Herve
    Member
    Posted 3 years ago #

    Hi everyone!

    I am trying to customize the output of my single articles.

    I would like that a <br clear="all"> would be added on each article after the first lines of my article (at the place where I add the more tag)

    At first, I thought that I could just add that into the_content in single.php
    <?php the_content(''<br clear="all">); ?>
    but it does not seem to work.

    Any idea how I could achieve that?

    Thank you for your help!

  2. Do you want it hooked into the more tag?

    Content content content<!--more--><br clear="all">
    
    More content blah blah blah

    or something else?

  3. sareiodata
    Member
    Posted 3 years ago #

    Try with css:

    .morelink{ display:block; clear:both; }

  4. Max Chirkov
    Member
    Posted 3 years ago #

    try this

    <?php
    global $more;    // Declare global $more (before the loop).
    $more = 1;       // Set (inside the loop) to display all content, including text below more.
    the_content('<br clear="all">');
    ?>
  5. Jeremy Herve
    Member
    Posted 3 years ago #

    Thank you all!

    @ipstenu yes indeed, that's what I'd like to achieve.

    @sareiodata Thanks, but won't this rather affect the more link that appears on index.php, instead of single.php

    @maxchirkov Thank you. I will give a try to these 2 solutions, and let you know how that works out!

  6. Jeremy Herve
    Member
    Posted 3 years ago #

    ok, coming back.

    I have tried your solution maxchirkov, and it does not seem to change anything I am afraid.

    @sareiodata, your solution indeed styles the "read more" tag appearing on my homepage (index.php).

    The read more tag is inserted in every article like this:
    <p><span id="more-5363"></span></p>
    Where 5363 is the id of the post. If only there was a way to hook something in there directly...

  7. It should be .more-link { } I thought...

    Working theory. Since this snippet will remove the link, maybe you can tweak it to add the line break?

    function remove_more_jump_link($link) {
    	$offset = strpos($link, '#more-');
    	if ($offset) {
    		$end = strpos($link, '"',$offset);
    	}
    	if ($end) {
    		$link = substr_replace($link, '', $offset, $end-$offset);
    	}
    	return $link;
    }
    add_filter('the_content_more_link', 'remove_more_jump_link');
  8. Will Anderson
    Member
    Posted 3 years ago #

    But there is no the_content_more_link filter when viewing a single post. Better, filter the_content and add a unique class to the "more" span using a RegEx replace.

    function add_more_span_class( $content ) {
        $content = preg_replace('/(more-[0-9]+)/', '$1" class="more-span', $content);
        return $content;
    }
    add_filter( 'the_content', 'add_more_span_class');

    Then you can add CSS to make that span clear.

    .more-span {
        display: block;
        clear: both;
    }
  9. Max Chirkov
    Member
    Posted 3 years ago #

    This works for me if I intentionally place the more tag into a post:

    function _my_custom_func($content){
    	global $post;
    	if(!is_single()){
    		return $content;
    	}
    	return str_replace('<span id="more-' . $post->ID . '"></span>', '<h1>more</h1>', $content);
    }
    add_filter('the_content', '_my_custom_func', 12);
  10. Max Chirkov
    Member
    Posted 3 years ago #

    Oops - replace the H1 tag with the <br clear="all">... I used h1 so I could see if it works.

  11. Will Anderson
    Member
    Posted 3 years ago #

    If you do that, the "more" links from archive pages will point to an invalid anchor. Is that what you want?

  12. Jeremy Herve
    Member
    Posted 3 years ago #

    Thank you all!

    To avoid the issue with invalid anchors, I simply changed the code provided by maxchirkov a bit:

    function _my_custom_func($content){
    	global $post;
    	if(!is_single()){
    		return $content;
    	}
    	return str_replace('<span id="more-' . $post->ID . '"></span>', '<span id="more-' . $post->ID . '"></span><br clear="all">', $content);
    }
    add_filter('the_content', '_my_custom_func', 12);

    That did the trick! Thank you again!

  13. Max Chirkov
    Member
    Posted 3 years ago #

    I haven't looked at the specifics of the code for archive pages, but I placed condition to return $content as is if the page is not a single post.

    Also, if you look at the get_the_content() function line #217 - there is no filter or variable within the span tags... so I assumed it's safe to simply remove them.

Topic Closed

This topic has been closed to new replies.

About this Topic