wp_trim_words() does not trim the_content() in WordPress

The problem lies in this line: <?php echo wp_trim_words( the_content(), 55, $moreLink); ?> You call the_content function in there. This function prints all the content and doesn’t return anything. It means that you print the content, and then pass an empty string to the wp_trim_words. It should be: <?php echo wp_trim_words( get_the_content(), 55, $moreLink); ?> … Read more

Load post with a different template?

you can do it like this: //add my_print to query vars function add_print_query_vars($vars) { // add my_print to the valid list of variables $new_vars = array(‘my_print’); $vars = $new_vars + $vars; return $vars; } add_filter(‘query_vars’, ‘add_print_query_vars’); then add a template redirect based on that query_var: add_action(“template_redirect”, ‘my_template_redirect_2322’); // Template selection function my_template_redirect_2322() { global $wp; … Read more

Change the output for [gallery] shortcode

The source for the gallery shortcode is in wp-includes/media.php. There are a couple of hooks in there that might work for you. Without knowing exactly what you want to do, it is impossible to be more specific. If that doesn’t work then you can remove the shortcode: remove_shortcode(‘gallery’); And add another gallery shortcode with the … Read more

stop blog page from using index.php?

Please consult the Template Hierarchy, and ensure that you are using the correct names for template files. index.php should be left as the default fallback for all other template files The site front page template file name is front-page.php. You need to rename your homepage.php as front-page.php The blog posts index page template file name … Read more

Apply template to custom post type

Typically I wouldn’t follow such a strong answer like the one @Milo provided with a post like this. Since I already had this code written for another project I thought I’d share. The code below does everything @Milo summarized in his answer and I’ve ported this across projects before with great success. Here’s the cheat … Read more