How do you check if a WordPress template file exist?

So I would add to the Answer the following: function foo_function() { $located = locate_template( ‘home.php’ ); if ( !empty( $located ) ) { // ‘home.php’ found in Theme, do something } } add_action(‘init’, ‘foo_function’); // remember to change both of the parameters above, first one for where you want the // action to happen … Read more

WP frontend output of custom textarea fields not respecting line breaks. In admin it’s OK

Explode your $options value by “/n” ( new line ), then do a echo in foreach: $options = get_option(‘my_custom_plugin_options’); $textarea = $options[‘my_custom_plugin_options_textarea’]; $lines = explode(“\n”, $textarea); foreach( $lines as $line ){ echo $line; } UPDATE #1 For reference, it’s possible to store this function in functions.php to use later in template files. function the_textarea_value( $textarea … Read more

Loading partial templates with AJAX/PJAX

If you’re concerned about the performance I would recommend using the WordPress API instead of trying to load markup using ajax. If you look at wp-includes/template-loader.php you can see how WordPress itself figures out which template to use. You could in theory just load that file, but you might have problems with template_redirect. require_once( ABSPATH … Read more

get page templates

Checking for get_page_templates() in the core, I found a workaround that doesn’t break the theme like: Fatal error: Call to undefined function get_page_templates() I’m using this just after <body> and works ok: $templates = wp_get_theme()->get_page_templates(); foreach ( $templates as $template_name => $template_filename ) { echo “$template_name ($template_filename)<br />”; }

How to Rename a Template File?

Chris gave me some good insight, and I appreciate the filter func. But I wound up changing the db through phpMyAdmin: UPDATE wp_postmeta SET meta_value=”new-filename.php” WHERE meta_value=”old-filename.php”;

Customizing get_the_excerpt() to specific length and “Read More” output.

To get a specific length you can use: wp_trim_words function. It has 3 parameters. Text to trim. Ex: get_the_content() Number of words. Ex: 295 What to append after end of the text. Ex: ” This means null. Use this: <span> <?php echo wp_trim_words( get_the_content(), 295, ” ); ?> <i><a style=”color:#1975D1;float:Right;” class=”title” href=”https://wordpress.stackexchange.com/questions/75069/<?php the_permalink() ?>” rel=”bookmark”>Click … Read more

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