post_grid_layout_element_{id}
used to render HTML output for each element on the grid item, where {id}
should replace with element id, like title, excerpt, and etc, list of elements here https://pickplugins.com/documentation/post-grid/elements/
Sample code for excerpt
add_action('post_grid_layout_element_excerpt', 'post_grid_layout_element_excerpt'); function post_grid_layout_element_excerpt($args){ $element = isset($args['element']) ? $args['element'] : array(); $elementIndex = isset($args['index']) ? $args['index'] : ''; $post_id = isset($args['post_id']) ? $args['post_id'] : ''; if(empty($post_id)) return; $layout_id = isset($args['layout_id']) ? $args['layout_id'] : ''; $post_excerpt = get_the_excerpt($post_id); $post_link = get_permalink($post_id); $link_target = isset($element['link_target']) ? $element['link_target'] : ''; $custom_class = isset($element['custom_class']) ? $element['custom_class'] : ''; $char_limit = isset($element['char_limit']) ? (int) $element['char_limit'] : 0; $read_more_text = isset($element['read_more_text']) ? $element['read_more_text'] : __('Read more', 'post-grid'); if($char_limit > 0){ $post_excerpt = wp_trim_words($post_excerpt, $char_limit, ''); } ?> <div class="element element_<?php echo esc_attr($elementIndex); ?> <?php echo esc_attr($custom_class); ?> excerpt "> <?php echo ($post_excerpt); ?> <?php if(!empty($read_more_text)): ?> <a target="<?php echo esc_attr($link_target); ?>" href="<?php echo esc_url_raw($post_link); ?>"><?php echo esc_html($read_more_text); ?></a> <?php endif; ?> </div> <?php }
Screenshot
Override existing output
remove_action('post_grid_layout_element_title', 'post_grid_layout_element_title'); add_action('post_grid_layout_element_title', 'post_grid_layout_element_title_custom'); function post_grid_layout_element_title_custom($args){ $element = isset($args['element']) ? $args['element'] : array(); $elementIndex = isset($args['index']) ? $args['index'] : ''; $post_id = isset($args['post_id']) ? $args['post_id'] : ''; if(empty($post_id)) return; $layout_id = isset($args['layout_id']) ? $args['layout_id'] : ''; $post_link = get_permalink($post_id); $post = get_post( $post_id ); $title = isset( $post->post_title ) ? $post->post_title : ''; //$title = get_the_title($post_id); $link_target = isset($element['link_target']) ? $element['link_target'] : ''; $custom_class = isset($element['custom_class']) ? $element['custom_class'] : ''; $char_limit = isset($element['char_limit']) ? (int) $element['char_limit'] : 0; $char_end = isset($element['char_end']) ? $element['char_end'] : '...'; $link_to = isset($element['link_to']) ? $element['link_to'] : 'post_link'; if($char_limit > 0){ $title = wp_trim_words($title, $char_limit, $char_end); } ?> <h2 class="element element_<?php echo esc_attr($elementIndex); ?> <?php echo esc_attr($custom_class); ?> title "> <?php if($link_to == 'post_link'): ?> <a target="<?php echo esc_attr($link_target); ?>" href="<?php echo esc_url_raw($post_link); ?>"><?php echo esc_html($title); ?></a> <?php else: ?> <?php echo esc_html($title); ?> <?php endif; ?> </h2> <?php }
Read more text
add_action('post_grid_layout_element_read_more', 'post_grid_layout_element_read_more_11022021'); function post_grid_layout_element_read_more_11022021($args){ $element = isset($args['element']) ? $args['element'] : array(); $elementIndex = isset($args['index']) ? $args['index'] : ''; $post_id = isset($args['post_id']) ? $args['post_id'] : ''; if(empty($post_id)) return; $read_more_text = isset($element['read_more_text']) ? $element['read_more_text'] : ''; echo $read_more_text; }