Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page

I found an answer by searching in similar posts and links. I added a line to fit my needs (I wanted to prevent my blog page to get highlited when on a custom post).See this line: unset($classes[array_search(‘current_page_parent’,$classes)]); Solution function add_parent_url_menu_class( $classes = array(), $item = false ) { // Get current URL $current_url = current_url(); …

Read more

Set template based on query in URL

There are a number of template filters available to override template selection. For a single post you can use the single_template filter: function wpa_single_template( $template ) { if( isset( $_GET[‘template’] ) ) { $template = locate_template( $_GET[‘template’] . ‘.php’, false ); } return $template; } add_filter( ‘single_template’, ‘wpa_single_template’ );

How to display error on specific template?

@PieterGoosen gave some good advice. Focus on that, But if you really wan it, then you can set debug ON temporarily on your website this way. In your wp-config.php use this instead. if ( isset( $_GET[‘debug’] ) && ‘debug’ == $_GET[‘debug’] ) { define( ‘WP_DEBUG’, true ); } Then access your website homepage/any page and …

Read more

Change directory where get_header(), get_footer() and get_sidebar() look for templates

Simple solution, use get_template_part(). For example: get_template_part( ‘partials/footer’ ); Which would get the footer.php inside the partials/ directory. Another example: get_template_part( ‘partials/footer’, ‘home’ ); Which would get the footer-home.php inside the partials/ directory. One more example: get_template_part( ‘partials/footer/blog’ ); Which would get the blog.php inside the partials/footer/ directory.

WordPress Template Hierarchy

You can use the dynamic filter {type}_template (where {type} is the current query type e.g. single, index etc.) found in get_query_template(): function wpse_204848_get_id_template( $template ) { if ( $post = get_queried_object() ) { if ( $_template = locate_template( “single-{$post->post_type}-{$post->ID}.php” ) ) $template = $_template; } return $template; } add_filter( ‘single_template’, ‘wpse_204848_get_id_template’ ); For a portfolio …

Read more

Remove header and footer but KEEP all css and js etc for a custom post template?

If someone needs something similar, I actually found an answer to my issue and it is to pass arguments to get_header() and get_footer(). <?php get_header(‘customposttype); ?> <div style=”width:500px;”> <?php $id = get_the_id(); echo do_shortcode( ‘[skwidget id=”‘ . $id . ‘”]’ ); ?> </div> <?php get_footer(‘customposttype’); ?> and copy header.php to header-{customposttype}.php and footer.php to footer-{customposttype}.php …

Read more

Turn query string to sub page

Put this code in your functions.php– function the_dramatist_url_rewrite() { global $wp_rewrite; add_rewrite_tag(‘%sub%’, ‘([^&]+)’); add_rewrite_rule( ‘^events/%year%/%monthnum%/%day%/%postname%/?’, ‘index.php/events/%year%/%monthnum%/%day%/%postname%?sub=$matches[1]’, ‘top’ ); } add_action(‘init’, ‘the_dramatist_url_rewrite’, 10, 0); The go to the permalinks page in the settings menu at dashboard and hit Save Changes button. Hope this is gonna help.

Dequeue script in template isn’t working

Move your project_dequeue_unnecessary_scripts() function to your functions.php file and add a conditional statement to determine if the appropriate template is being loaded. E.g.: // Remove Mobile Header function project_dequeue_unnecessary_scripts() { if ( is_page_template( ‘name-of-template.php’ ) ) { wp_dequeue_script( ‘enterprise-responsive-menu’ ); wp_deregister_script( ‘enterprise-responsive-menu’ ); } } add_action( ‘wp_print_scripts’, ‘project_dequeue_unnecessary_scripts’ ); I suspect that your function is …

Read more