0

My "About Me" widget on the sidebar is too long and I want to insert a "Read More" tag.

I can't find how to do it. Can anyone provide simple instructions? I can do basic HTML but can't seem to find where the code is for widgets.

  • Please share more information about your setup. Do you use a custom theme or a bought one? – Laxmana May 14 '17 at 15:44
  • Hi @Laxmana, I am using the Olsen Light theme. This is the sidebar.php text that's currently there: <div class="sidebar sidebar-right" role="complementary" itemtype="schema.org/WPSideBar" itemscope="itemscope"> <?php if( is_page() && is_active_sidebar( 'page' ) ) { dynamic_sidebar( 'page' ); } else { dynamic_sidebar( 'blog' ); } ?> </div><!-- /sidebar --> Anything more you need to know? – Helen Gregory May 14 '17 at 19:36
  • You could use wordpress.org/plugins/wp-showhide this plugin. It allows to wrap your text on the shortcode and shows hide/show effect as Read more – Aishan May 15 '17 at 8:38
2

It's pretty easy.

Usually your widget is supposed to be held on sidebar.php
In sidebar.php you may have been call the function the_content() to extract 'About Me' text.

In stead of calling the_content() you need to call your own created function [suppose, read_more()] which should be defined in functions.php like this way:

function read_more($limit){
    $post_content = explode(' ', get_the_content());
    $less_content = array_slice($post_content,0, $limit);
    echo implode(' ', $less_content);
}

Now, mentioning an argument, call the read_more()function in anywhere you need, perhaps in sidebar.php
Note that, first, needs to make Query and then call the function this way:

<?php
    $content_text = new WP_Query(array('post_type' => 'text'));
      while($content_text->have_post()) : $content_text->the_post();
?>
       <p> <?php read_more(15); ?> </p> 
       <p> <a href="<?php the_permalink(); ?>"> Read More </a> </p>
<?php endwhile; ?>

where, integer value indicates 15 number of words to be shown up there.

That's it.

  • Thank you perfectionist1 but that is too complicated for me! Is there not a plugin that will do the job? – Helen Gregory May 14 '17 at 18:24
  • This is the sidebar.php code as it stands: <div class="sidebar sidebar-right" role="complementary" itemtype="schema.org/WPSideBar" itemscope="itemscope"> <?php if( is_page() && is_active_sidebar( 'page' ) ) { dynamic_sidebar( 'page' ); } else { dynamic_sidebar( 'blog' ); } ?> </div><!-- /sidebar --> – Helen Gregory May 14 '17 at 19:39
  • In your case, you will find the function the_content() onto page.php and blog.php as well. If you unable to replace the code. Then you would share your code so that I can try to help you. – perfectionist1 May 15 '17 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.