WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] ID tag to read-more (11 posts)

  1. Sinopa
    Member
    Posted 2 years ago #

    Hi.

    Does anyone know how I can add an id tag to the read-more?

    <a href="http://localhost/?p=41#more-1" ID="MYMORESTYLE" class="more-link">

  2. cimeran
    Member
    Posted 2 years ago #

    function new_excerpt_more($more) {
      global $post;
      return '<a href="'. get_permalink($post->ID) . '" id="whatever">Read the Rest...</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    You can see more here.

  3. Sinopa
    Member
    Posted 2 years ago #

    Oh. Forgot to add that I use the_content, and not excerpt.

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    what is the purpose of adding a css id to the more link?

    - the link can be perfectly styled based on the css class .more-link;

    - using more than one post with this link on one web page would output multiple elements with the same css id, i.e. create invalid code.

    unless MYMORESTYLE is unique per post, in which case the next question is, where would it come from?

  5. Sinopa
    Member
    Posted 2 years ago #

    I'm sorry alchymyth, but I just need it without using a lot of time explaining why I need it.

  6. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    does it need to be unique per post?

  7. Sinopa
    Member
    Posted 2 years ago #

    That part I have fixed. I just need to add an id="" to the read more tag

  8. Sinopa
    Member
    Posted 2 years ago #

    *LOL* Ask and ye will receive a thousand questions in return, but ye will not receive an answer :D

  9. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    try this filter function:

    add_filter( 'the_content_more_link','more_link_css_id',10,2);
    function more_link_css_id($link,$link_text) {
    global $post;
    $link = '<a href="' . get_permalink($post->ID) . "#more-{$post->ID}\" class=\"more-link\" id=\"more-link-id-{$post->ID}\">$link_text</a>";
    return $link;
    }

    this example would add the css id #more-link-id-123

  10. Sinopa
    Member
    Posted 2 years ago #

    Thank you very much alchymyth :)

    I will try it right away :)

  11. Sinopa
    Member
    Posted 2 years ago #

    OMG! It worked! Thank you, Thank you, Thank you alchymyth :)
    Been trying to find a solution on Google, but didn't find any.

    Thank again alchymyth. You saved my day :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags