Category before Title
-
I am trying to put the Category before the title – is that possible?
The page I need help with: [log in to see the link]
-
You will need to use the output filter to change the order of the post elements.
See the examples here: https://www.billerickson.net/code/using-display-posts-shortcode-output-filter/
I’ve followed the instructions and added the code below before the /?> in the functions.php file.
/**
* DPS – Move category before title
* @see https://www.billerickson.net/code/using-display-posts-shortcode-output-filter
*
*/
function be_dps_move_category_before_title( $output, $original_atts, $image, $category_display_text, $title, $date, $excerpt, $inner_wrapper, $content, $class ) {
$output = ‘<‘ . $inner_wrapper . ‘ class=”‘ . implode( ‘ ‘, $class ) . ‘”>’ . $image . $category_display_text . $title . $excerpt . $content . $date . ‘</’ . $inner_wrapper . ‘>’;
return $output;
}Not seeing any change in the site though, category still follows after the other elements (title, date, author).
Am I doing something wrong?
You need to include the last line:
add_filter( 'display_posts_shortcode_output', 'be_dps_move_image_after_title', 10, 9 );You defined the function, but the last line applies that function to the shortcode’s output.
When I try that the posts disappear – doing something wrong?
/**
* DPS – Move category before title
* @see https://www.billerickson.net/code/using-display-posts-shortcode-output-filter
*
*/
function be_dps_move_category_before_title( $output, $original_atts, $image, $category_display_text, $title, $date, $excerpt, $inner_wrapper, $content, $class ) {
$output = ‘<‘ . $inner_wrapper . ‘ class=”‘ . implode( ‘ ‘, $class ) . ‘”>’ . $image . $category_display_text . $title . $excerpt . $content . $date . ‘</’ . $inner_wrapper . ‘>’;
return $output;
}add_filter( ‘display_posts_shortcode_output’, ‘be_dps_move_image_after_title’, 10, 9 );
It looks like your function names don’t match. At the top you’re using be_dps_move_category_before_title() as the name, but in the add_filter line you’re using be_dps_move_image_after_title().
Change the code to this:
/** * DPS – Move category before title * @see https://www.billerickson.net/code/using-display-posts-shortcode-output-filter * */ function be_dps_move_category_before_title( $output, $original_atts, $image, $category_display_text, $title, $date, $excerpt, $inner_wrapper, $content, $class ) { $output = ‘<‘ . $inner_wrapper . ‘ class=”‘ . implode( ‘ ‘, $class ) . ‘”>’ . $image . $category_display_text . $title . $excerpt . $content . $date . ‘</’ . $inner_wrapper . ‘>’; return $output; } add_filter( ‘display_posts_shortcode_output’, ‘be_dps_move_category_before_title’, 10, 9 );-
This reply was modified 8 years, 6 months ago by
Bill Erickson.
-
This reply was modified 8 years, 6 months ago by
Bill Erickson.
Tried that – seemed to cause a page issue, the site wouldn’t load with that code added, any ideas?
-
This reply was modified 8 years, 6 months ago by
The topic ‘Category before Title’ is closed to new replies.