Change site template from php

If I understand your question, you should use this inside your foreach: $argument_to_pass_to_switch_theme = $theme->get_stylesheet(); Just taking a look at the documentation: The function wp_get_themes()… “…returns an array of WP_Theme objects based on the argument.” This class WP_Theme has a method get_stylesheet(), which… “…returns a string with the directory name of the theme’s “stylesheet” files, … Read more

Load template inside a parent template

if ( condition ) { get_template_part( ‘path/to/template’, ‘mobile’ ); } else { get_template_part( ‘template’, ‘mobile’ ); // in rootpath } You can also intercept the behavior for get_template_part() with an action hook: // Source in get_template_part do_action( “get_template_part_{$slug}”, $slug, $name ); function wpse21352_template_part_cb( $slug, $name ) { switch ( $name ) { case ‘mobile’ : … Read more

Create a WordPress template without navigation and footer

Don’t remove get_header(). Duplicate the header.php to header-{custom-name}.php, let’s say (header-nonavfooter.php) then in the template file replace get_header() with get_header(‘nonavfooter’). In the new header file (header-nonavfooter.php) remove the code related to navigation. Do the same for the footer.php also(Create a new footer.php and remove the footer parts that you don’t need), remember not to remove … Read more

Prevent private post 404

According to the Content Visibility page, Private posts are visible only to those with sufficient permission levels. WordPress doesn’t expose them to non-logged-in users at all, hence (presumably) the 404. If you want to display a limited preview to non-members, instead of setting the post to Private, you could try something like this: add_filter( ‘the_content’, … Read more

Modifying searchform.php and search.php to have two kinds of searches

For anyone trying to achieve something similar, here’s how I solved it: In searchform.php, duplicate the form, as such: <form method=”get” id=”searchform” action=”<?php echo esc_url( home_url( “https://wordpress.stackexchange.com/” ) ); ?>”> <input type=”text” name=”s” id=”s” placeholder=”<?php esc_attr_e( ‘Search by Post’ ); ?>” /> <input type=”hidden” name=”search-type” value=”posts” /> <button type=”submit” name=”submit” id=”searchsubmit” value=”<?php esc_attr_e( ‘Search’ ); … Read more