Conditionally display different images before the content in a page template

You could try the loop_start hook depending on what position you want the image and use the code in your functions file. add_action(‘loop_start’, function() { if(is_page(10)) { echo do_shortcode(‘[plugin_shortcode 1 …..]’); } else if (is_page(11)) { echo do_shortcode(‘[plugin_shortcode 2 …..]’); } else if (is_page(15)) { echo do_shortcode(‘[plugin_shortcode 3 …..]’); }}); Or you could pull the … Read more

Custom Post Type with Templates using Meta Boxes?

I’d recommend using the template_include filter as opposed to template_redirect, as using this hook means that you don’t redirect the user but rather just present them with the template that is requierd. add_filter(‘template_include’, ‘my_custom_template_redirect’, 99); function my_custom_template_redirect($template){ global $post; if(is_single() && ‘campaign’ == get_post_type($post)){ $page_template = get_page_template(); $new_template = locate_template( array( ‘subfolder/’ . $page_template . … Read more

Create a page template with No Footer

The correct way to load footer-none.php is: get_footer(“none”); Anyway, I think it can be better to use wp_footer() (required function on any frontend page) directly in the page template file so you don’t need to load any empty footer template (assuming you load all required HTML tags in the page template, for example closing body … Read more

Inconsistent `body_class()` function

The comment from @milo prompted me to take a closer look, and I realised I was chasing a false positive. The About page and Contact page were actually displaying the correct behaviour; it was Home and Services that were wrong. It seems at some point those two pages did have custom page templates, which were … Read more

Custom post type archive page template

I have managed to resolve this by adding in a custom rewrite into the functions file: // Add custom rewrite rules to handle things like years in custom post archives function add_rewrite_rules($aRules) { $aNewRules = array( ‘news/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?$’ => ‘index.php?post_type=clientnews&year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]’, ‘news/([0-9]{4})/([0-9]{2})/?$’ => ‘index.php?post_type=clientnews&year=$matches[1]&monthnum=$matches[2]’, ‘about-us/other-news/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?$’ => ‘index.php?post_type=othernews&year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]’, ‘about-us/other-news/([0-9]{4})/([0-9]{2})/?$’ => ‘index.php?post_type=othernews&year=$matches[1]&monthnum=$matches[2]’ ); $aRules = $aNewRules + $aRules; return … Read more

Hook for when a page template is changed

If you want to toggle the editor “on the fly”, you’ll need to revert to a pure JavaScript solution, and only ever “visually” hide it (as opposed to removing it server-side): function wpse_189693_hide_on_template_toggle() { $screen = get_current_screen(); if ( $screen && $screen->id === ‘page’ ) : ?> <script> jQuery( “#page_template” ).change( function() { jQuery( “#postdivrich” … Read more

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