get_header(), get_footer() from plugin template

Old question, but maybe my answer will help someone. Short answer is: use load_template() function with full file server path as first argument passed to it. Long answer: get_header() using the function locate_template() which uses the function load_template() which uses the function require_once(). Thus, to load the header layout from a plugin or any other … Read more

WordPress Picks Up Wrong Template for Custom Post Type Archive Page

You can manage this via the template_include hook. add_filter( ‘template_include’, ‘cats_and_dogs_living_together’, 99 ); function cats_and_dogs_living_together( $template ) { if ( is_post_type_archive( array ( ‘cat’, ‘dog’ ) ) ) { $new_template = locate_template( array( ‘archive-dog.php’ ) ); if ( ” != $new_template ) { return $new_template; } } return $template; } Hope this helps!

Custom page with queries returns 404

WordPress rewrites standard wordpress urls from /category/post-name/ or whatever your selected permalink type is, into index.php?…. You are adding query vars to a link that is already getting rewritten into index.php?… and thus you are getting a 404. My advice to you would be to use something similar to an already asked question at Custom … Read more

Custom URL redirect in WP

The problem is with this expression: filter_var($url, FILTER_VALIDATE_URL) !== true which should or could be written as just: filter_var($url, FILTER_VALIDATE_URL) Because the PHP manual for filter_var() says: Returns the filtered data, or FALSE if the filter fails. which means, with a valid URL, filter_var() does not return a boolean; hence filter_var($url, FILTER_VALIDATE_URL) !== true never … Read more

How can I add text to a specific ‘Edit Page’?

To do this you would indeed have to include some code in the functions.php of your theme. You can use admin_notices to add a note to this specific page like this: add_action( ‘admin_notices’, ‘wpse332074_donotedit’ ); function wpse332074_donotedit () { $screen = get_current_screen(); if ($screen->post_type == ‘page’) { $variable = $_GET[‘post’]; if ($variable == id_of_page_as_integer) { … Read more

How do I get the page template name chosen?

I picked the following code from an answer here, https://stackoverflow.com/questions/2544870/remove-main-editor-from-wordpress-edit-page-screen/42093956. I tweaked the code to remove the classic editor on pages using default page template. And added the comments. function remove_editor_init() { $post_id = 0; if ( isset( $_GET[‘post’] ) ) { $post_id = $_GET[‘post’]; } $template_file = get_post_meta( $post_id, ‘_wp_page_template’, TRUE ); // var_dump($template_file) … Read more

wp_redirect goes to infinity loop

Us this code instead: function redirect_location(){ global $wp; $current_url = home_url( $wp->request ); $UserDetails = unserialize(file_get_contents( ‘http://www.geoplugin.net/php.gp?ip=’ ) ); $userCountry = $UserDetails[‘geoplugin_countryCode’]; if($userCountry == ‘AR’){ $url = home_url(‘/ar/’); } else if($userCountry == ‘FR’){ $url = home_url(‘/fr/’); } else { $url = home_url(‘/in/’); } if( ( is_page() || is_home() ) && ( strpos( $current_url, $url ) … Read more

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