Is it safe to include a javascript file in a template’s php file?

As @N00b mentioned Yes, it is safe adding a JS script as long as it doesn’t include any sensitive information. JS is fully exposed to client, you shouldn’t do it anyway. But your situtaion it is better to create a site specific custom plugin and add JS using it. Example : function themeslug_enqueue_style() { wp_enqueue_style( … Read more

template_include not loading -instead goes to index.php

in order for the discography rule to work, I changed the rule from: add_rewrite_rule( ‘artists/([^/]+)/discography/?$’, ‘index.php?album_artist=$matches[1]&discography=yes’, ‘top’); to this : add_rewrite_rule( ‘artists/([^/]+)/discography/?$’, ‘index.php?artists=$matches[1]&discography=yes’, ‘top’); What the original rule was doing was pointing to the Artist’s Name and not the Artists custom post type, thus failing to redirect to the template. Thanks a lot to @RachelCarden … Read more

WordPress rewrite rules for state and city

Wasn’t as hard as I thought. Here’s the working example, in case anyone finds it helpful: function em_query_vars($vars) { array_push($vars, ‘state’); array_push($vars, ‘city’); return $vars; } add_filter(‘query_vars’,’em_query_vars’); function em_rewrite() { add_rewrite_rule( ‘^state/([^/]*)/([^/]*)/?’, ‘index.php?state=$matches[1]&city=$matches[2]’, ‘top’ ); add_rewrite_rule( ‘^state/([^/]*)/?’, ‘index.php?state=$matches[1]’, ‘top’ ); add_rewrite_tag(‘%state%’,'([^&]+)’); add_rewrite_tag(‘%city%’,'([^&]+)’); } add_action(‘init’, ’em_rewrite’); function em_templates($template) { global $wp_query; if (isset($wp_query->query_vars[‘state’]) && isset($wp_query->query_vars[‘city’])) { … Read more

Template Include crashing browser

You have a couple mistakes in your code: is_archive() does not accept any parameters is_archive() does not accept any parameters. If you want to check if this is the archive of a custom post type, use is_post_type_archive( $post_type ) Instead of using include( plugin_dir_path( __FILE__ ) . ‘my-template.php’);, use dirname( __FILE__ ) . ‘my-template.php’; Single … Read more

Get template name by full URL

You can make use of the global $template which holds the complete path of the current template being use to display a page. From there you can manipulate the value to get the name of the template As example, the value of $template looks like this: (This is on my localhost on my PC) E:\xammp\htdocs\wordpress/wp-content/themes/pietergoosen2014/page-test.php … Read more

Render a different post/template from within the template_include action?

This was a bit tricky to solve your problem. the template_include filter executed after the main query processed the current request. If you can filter the current request (query_vars) and update it accordingly then WordPress will display any post/page you wanted to… Simply filter the query_vars with the request filter. Check the following snippet. But … Read more

template_include for search.php makes WordPress think its on the home page

Your problem is that you are not resetting all the needed query variables, like WP_Query::$is_page, WP_Query::$is_single and WP_Query::$is_archive. Also note that ‘pre_get_posts’ is fired for all queries, the main and the secondaries, so you should check that you are working on the main query. Finally, when you get data from $_GETyou should sanitize it before … Read more

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