WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Change wording of Older Posts in Twenty twelve (14 posts)

  1. neophyte50
    Member
    Posted 1 year ago #

    Hi!

    I would like to changed the Older Posts at the bottom of the page and keep just the arrow! Can anyone help? Thanks a lot!

  2. DJDoubleXL189
    Member
    Posted 1 year ago #

    This is editable within the theme files, but I'd highly recommend using a child theme unless you don't plan on updating the Twenty Twelve theme.

  3. Shaun Scovil
    Member
    Posted 1 year ago #

    Unfortunately, WordPress does not provide a filter for the previous & next post links. You would need to filter the_content and make the change using a function like this in your functions.php file:

    function prev_next_links_06122013( $content ) {
        $content = str_replace( 'Older Posts', '', $content );
        $content = str_replace( 'Newer Posts', '', $content );
        return $content;
    }
    add_filter( 'the_content', 'prev_next_links_06122013' );

    That function would remove the words "Older Posts" and "Newer Posts" from each post/page.

    Also, since str_replace is case sensitive, it won't remove the phrase "older posts" or "Older posts" if that were in the content of the post or page.

  4. Shaun Scovil
    Member
    Posted 1 year ago #

    And yes, use a child theme! :-)

  5. neophyte50
    Member
    Posted 1 year ago #

    Thanks! I have a child theme and added that code to the functions.php and it still shows older posts... hmmm...

  6. Shaun Scovil
    Member
    Posted 1 year ago #

    Oh, right. Those links are not a part of the post content; they are added by the page template after the_content(). My bad.

    I did find this article, which suggests that this would work:

    function prev_link_06122013( $content ) {
        $content = str_replace( 'Older Posts', '', $content );
        return $content;
    }
    add_filter( 'previous_post_link', 'prev_link_06122013' );
    
    function next_link_06122013( $content ) {
        $content = str_replace( 'Newer Posts', '', $content );
        return $content;
    }
    add_filter( 'next_post_link', 'next_link_06122013' );
  7. neophyte50
    Member
    Posted 1 year ago #

    So I should not post this on the functions.php? but i don't have the_content() in my index.php. I'm relatively new to this, sorry for asking so many questions! Thanks a lot for your help!

  8. Shaun Scovil
    Member
    Posted 1 year ago #

    Yes, the code I gave you should go in your child theme functions.php, after the opening <?php tag.

    (And yes, your index.php probably uses the_excerpt(); instead. Sorry, my first solution was a bit rushed and not very well thought out.)

  9. neophyte50
    Member
    Posted 1 year ago #

    It still doesn't work. I'm probably doing something wrong... here's my website: http://www.laurinliu.ca

    I've added that text to the functions.php file, uploaded on the ftp directory of my child theme, and refreshed my page and the "older posts" still appear.

    Thanks for all your help, much appreciated!

  10. Shaun Scovil
    Member
    Posted 1 year ago #

    Sorry, I guess I should probably test my code before I post it! :-)

    Turns out, those filter hooks only work when the singular functions next_post_link() and previous_post_link() are used.

    You could just copy index.php over from the parent theme into your child theme directory, and change this on line 28:

    <?php twentytwelve_content_nav( 'nav-below' ); ?>

    ...to something like this:

    <?php my_child_theme_content_nav( 'nav-below' ); ?>

    Then, in your functions.php file, add this:

    function my_child_theme_content_nav( $html_id ) {
    	global $wp_query;
    
    	$html_id = esc_attr( $html_id );
    
    	if ( $wp_query->max_num_pages > 1 ) : ?>
    		<nav id="<?php echo $html_id; ?>" class="navigation" role="navigation">
    			<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
    			<div class="nav-previous alignleft"><?php next_posts_link( __( '<span class="meta-nav">←</span>', 'twentytwelve' ) ); ?></div>
    			<div class="nav-next alignright"><?php previous_posts_link( __( '<span class="meta-nav">→</span>', 'twentytwelve' ) ); ?></div>
    		</nav><!-- #<?php echo $html_id; ?> .navigation -->
    	<?php endif;
    }

    This way, you are creating a modified version of the Twenty Twelve theme function that outputs the pagination links, and calling your new function from your template files.

  11. neophyte50
    Member
    Posted 1 year ago #

    Hey Shaun!

    It still doesn't work. I've even uploaded the plugin WP-Paginate, which would keep numbers and arrows and it doesn't work either. I am wondering, would it be possible that i have other files affecting my functions.php file, like in the hierarchy?

    Currently, my child theme directory contains:
    content.php
    style.css
    category.php
    index.php
    single.php
    category.php
    index.php
    fr_FR.mo

    thanks so much! there must be something i'm not doing right...

  12. neophyte50
    Member
    Posted 1 year ago #

    Oh wow, I'm really sorry but it seems like my child theme wasn't activated!!! And when I did activate it, the twenty twelve theme wasn't there, so I have a lot of work to do!

  13. neophyte50
    Member
    Posted 1 year ago #

    Hey Shaun! So I tried all of the above on my now working child theme and the last suggestion worked (with modifications to the index.php)!!! you can check it out at laurinliu.ca!

    Thanks soooo much! Especially for your patience!

  14. Shaun Scovil
    Member
    Posted 1 year ago #

    Glad to help!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.