How to get IDs for objects in menu branch?

I am lazy to write supporting logic from scratch so I am reusing functions from linked answer on branches: /** * Retrieve IDs of posts in branch of menu. * * @param mixed $menu * @param string $branch_title * * @link http://wordpress.stackexchange.com/questions/2802/display-a-portion-branch-of-the-menu-tree-using-wp-nav-menu * * @return array */ function get_post_ids_from_menu_branch( $menu, $branch_title ) { $menu_object = … Read more

Page template in two level deep folder

WordPress will only search one level deep (*See below for details) from the root directory of the theme for page (and post) templates. However, the array of templates can be filtered using the theme_{$post_type}_templates filter, so you can add deeply nested templates on your own: // See WP_Theme::get_page_templates /** * Filters list of page templates … Read more

Dynamic template serving, change theme_root using add_filter from current theme

You could also write your own simple get_template_part alias function: The following allows 3 subfolders for template parts that sit in a theme root folder named devices. <?php // STYLESHEETS function print_device_styles( $client=”desktop” ) { $client = apply_filters( ‘set_theme_client’, $client ); wp_enqueue_style( $client.’-css’ ); } add_action( ‘wp_head’, ‘print_device_styles’, 11 ); // TEMPLATE PARTS function get_device_template_part( … Read more

Assign single template to multiple custom post types?

You can filter template_include and pass your custom template as return value depending on your own conditions. Sample code, not tested: add_filter( ‘template_include’, function( $template ) { // your custom post types $my_types = array( ‘photography’, ‘painting’ ); $post_type = get_post_type(); if ( ! in_array( $post_type, $my_types ) ) return $template; return get_stylesheet_directory() . ‘/single-photography.php’; … Read more

How to add custom content template part for a custom post type on main query using a plugin

Background Unfortunately get_template_part() function doesn’t have any suitable filter to achieve what you want. It’s possible to use the get_template_part_{$slug} action hook to inject template parts, however, without any change to your theme or a child theme, the original template part will be added anyway. So this way you’ll not be able to replace existing … Read more

Ways to have multiple front-page.php templates that can be swapped out?

One way is to have a single front-page.php and then using get_template_part(), to show different content based on user choice. Rough code: get_header(); $layout = get_option( ‘front_page_layout’, ‘default’ ); get_template_part( ‘front-page’, $layout ); get_footer(); After that you need to create a file for every layout, they should be called, something like: front-page-one.php front-page-two.php front-page-three.php front-page-default.php … Read more

Overwrite theme file from plugin

WordPress way (recommended): In your plugin, use the WordPress theme_file_path filter hook to change the file from the plugin. Use the following CODE in your plugin: add_filter( ‘theme_file_path’, ‘wpse_258026_modify_theme_include_file’, 20, 2 ); function wpse_258026_modify_theme_include_file( $path, $file=”” ) { if( ‘includes/example-file.php’ === $file ) { // change path here as required return plugin_dir_path( __FILE__ ) . … Read more

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