Loading page content into a variable in template

You can always use the output buffering to store the printing contents in a variable. function return_get_template_part($slug, $name=null) { ob_start(); get_template_part($slug, $name); $content = ob_get_contents(); ob_end_clean(); return $content; } $content = return_get_template_part(‘content’, ‘page’); This would be most preferable to keep using the get_template_part() right now. An alternative would be to use locate_template() function but it … Read more

How to consolidate multiple static page templates into one dynamic one?

Personally, I build everything within index.php of each template. I then do conditional checks. Example: if(is_front_page()){ // Home page layout } elseif(is_page()){ // General page layout if(is_page(‘contact’)){ // Page layout specific to the contact page } elseif(is_page(‘about’)){ // Page layout specific to the about page } } Read more on conditional tags.

Overriding page template using page_template filter

From your question, it seems you’re trying to override the single template of a custom post type. If so, the filter you want to use is single_template and not page_template: function single_page_template($single_template) { global $post; if ($post->post_type == ‘dwqa-question’) { $single_template = get_stylesheet_directory() . ‘/page-question.php’; } return $single_template; } add_filter( ‘single_template’, ‘single_page_template’ ); I once … Read more

Password protected posts redirects

TL;TR? Spoiler alert – hover over the next blockquote to expose it. Building an archive that is easily filterable by the currently entered password is nothing that is easy and surely not elegant buildable. The solution involves a secondary query and a small plugin, but it works. All errors and wrong paths are shown as … Read more

How to remove all styles for certain page template?

You can remove specific styles and java scripts for specific page template like below. Add the code into the functions.php file of your current theme. To see the list of all JS and CSS you may want to use a plugin like this: https://wordpress.org/plugins/debug-bar-list-dependencies/ /** * Remove specific java scripts. */ function se_remove_script() { if … Read more

When is get_template_part() preferable to simply using the template.php files?

A recommended approach for using get_template_part would be for including bits of code that would otherwise be repeated frequently in all your templates. Like if you had conditionals defined within your loop that you wanted to include in archive.php, search.php, single.php etc. It also allows child themes to override that file and include additional more … Read more

is_page_template not working

is_page_template() will only tell you if the page is using a custom page template. Meaning a template that was created by adding the Template Name: comment to the file and selecting it from the Template dropdown, as described here. The function works by checking the post meta for which template was selected. If you have … Read more

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