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

How do I add a body class to specific pages?

add_filter(‘body_class’,’cp_new_body_classes’); function cp_new_body_classes($classes) { if( !is_page_template() ) $classes[] = ‘reg-page’; return $classes; } The problem was that you are only returning the classes if !is_page_template(), but you want to return the classes always as it contains the other classes you didn’t add yourself in an array, you just want to add some then return them … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)