custom post type single page template not working

Please see the Template Hierarchy. There is no template-portfolio.php template. It needs to be archive-portfolio.php. Also, you should not be using a custom query*. Use the main query in your post type archive templates. WordPress already queries the correct posts for you. So remove: $portfolio = new WP_Query(‘post_type’=> ‘portfolio’); And replace: while ($portfolio-> have_posts() ) … Read more

Force template on page load

This question is quite difficult to understand. Do you mean you want to make generic template pages Programmatically? There are a few ways to do this. If you have a page built on the backend, you can create a file within your theme folder called page-{page-name}.php. For instance, for a page called about, you should … Read more

Custom template not working for existing pages [closed]

as a solution, you can fully automate the selection of a template for a group of pages using slug names: add_filter(‘request’, function( $vars ) { $slug = explode(“https://wordpress.stackexchange.com/”, explode(‘?’, $_SERVER[‘REQUEST_URI’])[0]); array_pop ($slug); $temp_base = “…first_part_template_name…”; $temp_slug = array_pop ($slug); if (file_exists(get_template_directory().”https://wordpress.stackexchange.com/”.$template.’-‘.$temp_cat.’.php’)) { get_template_part( $temp_base, $temp_slug ); } }

Read more button not working

From the Codex: Excerpts (teasers) can be shown on WordPress through two methods: The first, keeping the the_content() template tag and inserting a quicktag called more at your desired “cut-off” point when editing the post. The second, by replacing the the_content() template tag with the_excerpt(). If one of those conditions is met, and you are … Read more

How to read a page’s “Shortcodes” from the Template File?

Parsing shortcodes from strings WordPress parses and replaces shortcodes from a piece of content via the do_shortcode function. This function, in turn, calls get_shortcode_regex, which returns the regular expression for matching shortcodes in a string. Using this function, we can get a list of all shortcodes ourselves: $pattern = get_shortcode_regex(); preg_match_all( “/$pattern/s”, $content, $matches ); … Read more

Make default template two columns?

1. Add .php in wp-content/themes/ Write <?php /** * Template Name: <subpage-name>, left sidebar * Description: A one-colum template with left sidebar for <subpage-name> ONLY */ get_header(); ?> 2. Copy full-width page basic codes. 3. Add new div for <div id=”main” class=”<subpage-name>-right clearfix” role=”main”> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( ‘content’, … Read more

Page.php vs Single.php

Edit Based on this comment: commenting out comments_template works. The problem lies in the template markup in comments.php. The likely reason that you see it in some output and not others is likely because you’ve got comments enabled in one context, and not in the other. Try comparing single posts with comments enabled vs disabled, … Read more