[contact-form-7 id="24078" title="Feedback EN"]

Featured templates

WordPress Cherry 3.x. How to make read more links of “post_grid” shortcode open in new tab

This tutorial shows how to edit posts_grid shortcode so that Read More links and titles of posts opened in new tab.

WordPress. How to make read more links of “post_grid” shortcode open in new tab

In order to change shortcode behavior, you will need to edit the shortcode source code in the child theme, i.e. in the wp-content/themes/themeXXXXX/includes directory on server:

  1. Open the wp-content/themes/themeXXXXX/includes directory and check if there’s already shortcodes/posts-grid.php file on server.

  2. In case the file is missing, open the custom-function.php file and check if there’s already posts_grid code in the file: look for the posts_grid with Ctrl/Cmd+F5 hotkeys.

  3. In case the code is missing, open the posts-grid.php file located in the wp-content/plugins/cherry-plugin/includes/shortcodes directory on server and copy the code that starts with:

    function posts_grid_shortcode( $atts, $content = null, $shortcodename = '' ) {

    And ends with:

    add_shortcode('posts_grid', 'posts_grid_shortcode');
  4. Paste the code at the bottom of custom-function.php file before the closing ?> tag. Save changes in the file.

  5. Find the posts title link in the source code:

    <a href="'.get_permalink($post_id).'" title="'.get_the_title($post_id).'">';
    			$output .= get_the_title($post_id);
    		$output .= '</a>
  6. In order to open link in new tab, add target=”_blank” into the link code:

    <a target="_blank" href="'.get_permalink($post_id).'" title="'.get_the_title($post_id).'">';
    			$output .= get_the_title($post_id);
    		$output .= '</a>
  7. To modify the Read More button link, find the button link code which is the following:

    <a href="'.get_permalink($post_id).'" class="btn btn-primary" title="'.get_the_title($post_id).'">';
    				$output .= $link_text;
    			$output .= '</a>
  8. Add the same target=”_blank” attribute to the link code:

    <a target="_blank" href="'.get_permalink($post_id).'" class="btn btn-primary" title="'.get_the_title($post_id).'">';
    				$output .= $link_text;
    			$output .= '</a>
  9. Save changes in the custom-function.php file. Refresh the page with Ctrl/Cmd+F5 hotkeys to see changes on the site.

Feel free to check the detailed video tutorial below:

WordPress. How to make read more links of “post_grid” shortcode open in new tab