How to handle a missing page.php?

The only required template in a WordPress theme is the index.php. And a comments.php if comments are supported. Following the template hierarchy, all other files, including page.php, will fall back to the index.php. When a theme doesn’t have a page.php, look at the index.php. There you will find the basic structure for its content. In … Read more

Adding PHP/HTML code inside page from custom template

This is how to code the shortcode function foobar_func( $atts ){ return “foo and bar”; } add_shortcode( ‘foobar’, ‘foobar_func’ ); And to execute a function using output buffering add_shortcode( ‘shortcode_tag’, ‘function_name’ ); function function_name($atts) { ob_start(); // Add your code $var = ob_get_contents(); ob_end_clean(); return $var; }

Child page in custom post throws 404 page not found

It turns out the WordPress permalink structure works perfectly well for custom types, e.g. example.com/recipes/lunch/sandwich/. This works exactly as expected if you set ‘hierarchical’ => true. What I was originally trying to do was unnecessarily difficult to execute, and requires properly setting up a custom permalink structure to avoid 404 errors. I advise you stick … Read more

How to list all titles of posts on a specific page?

Paste this into your page template. It will output a list of all posts (without pagination). <?php // the query $all_posts = new WP_Query( array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1 ) ); if ( $all_posts->have_posts() ) : ?> <ul> <?php while ( $all_posts->have_posts() ) : $all_posts->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/240419/<?php the_permalink(); ?>”><?php … Read more

How to edit 404 content via wp editor?

Found a way. Create a regular page for 404 content, say ‘Page not found’; In your 404.php file, get that page data and then write down your content or whatever… For example: $page = get_page_by_title(“Page not found”); if($page) echo apply_filters(‘the_content’,$page->post_content); Obviously, you can do a lot more…

Adding a post shortcode to a page template?

To use shortcode in a PHP file (outside the post editor) you have the handy little function do_shortcode(); so in your case you use: <?php do_shortcode(‘[mingleforum]’); ?> Update: following the first comment, I figured its publicly known for some reason, if you are expecting output from the shortcode then echo it out. <?php echo do_shortcode(‘[mingleforum]’); … Read more