Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter valandor

    (@valandor)

    Or a more elegant way to do so. It’s mixed in with a function to wrap the more link in a div.

    function wrap_readmore($more_link)
    {
        //Check if link contains default (more...), if it does replace with Read More
        if(preg_match('(more…)', $more_link)){
            $more_link = str_replace('(more…)', 'Read More', $more_link);
        }
    	return '<div class="small-12 columns text-center">'.$more_link.'</div>';
    }
    add_filter('the_content_more_link', 'wrap_readmore');
    Thread Starter valandor

    (@valandor)

    I found the answer to my problem.

    Inside my function.php file I needed

    function my_the_post_action($post_object) {
        //Set Default Link Text
        $link_text = 'Default';
    
        $post = $post_object->post->post_content;
        if (preg_match('<!--more ' . '(.*?)' . '--> ', $post, $matches)) {
            //Returns Link Text String If Found
              return $matches[1];
        }else{
             return $link_text;
        }
    }
    add_action('loop_start', 'my_the_post_action');

    Then inside my template file I.E. index.php all I need to for my post content is

    the_content(my_the_post_action($post_object))

    This may not be the most elegant way of handling this, but it’s the only way I could find to get the post content prior to the more link being created. This will pass the desired default text into the_content() to change the read more link dynamically while allowing me to set a custom default more link. This will save time on creating posts instead of having to remember to say <–more {Something Custom} –>

    Thread Starter valandor

    (@valandor)

    Hi Peninah,

    I currently have that in my functions.php however this will replace all instances of the read more tag with the texteam inside the function. If you supply the generic read more tag with attributes it will change the text of the read more link.

    So ‘<!–more–>’ would display the wp default text of (more…) and ‘<!–more Read This –>’ would display Read This. I want to set the default text to something other than (more…)

    This would allow me to keep the functionality of the original read more tag which allows flexibility that I could need.

    Thread Starter valandor

    (@valandor)

    Hi sanchitkhera7,

    I really didn’t do much work on this mainly because I decided to just develop my site rather and use WordPress for the back-end. I’ll spend some time today and tomorrow working on this and let you know how it turns out and if it works I’ll let you know what I did to get it working.

    Thread Starter valandor

    (@valandor)

    Thank you for the response. I will go ahead and try this and let you know how this works out in case anyone else is having issues with this.

    Thank you again!

Viewing 5 replies - 1 through 5 (of 5 total)