Articles of template include

Get template name by full URL

Is There Any Way to get the template Name By full URL for example If the full url is www.example.com/hello-world I need a function that return the template name (page.php) I know that WordPress matches every url with regular expression to determine the query and decide which template to include. That’s exactly what I need, […]

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

I want to include some jquery plugin files to my wordpress multisite install. My solution involved creating a specific template file for the pages that required these jquery plugins. Below is the line of code that includes my javascript file which I have placed at the last line of the template file. <script type=”text/javascript” src=”<?php […]

template_include not loading -instead goes to index.php

I have the following code: <?php function ex_rewrite_rules(){ //discography query variable rewrite add_rewrite_rule( ‘artists/([^/]+)/discography/?$’, ‘index.php?album_artist=$matches[1]&discography=yes’, ‘top’); //albums rewrite rule add_rewrite_rule( ‘artists/([^/]+)/discography/([^/]+)/?$’, ‘index.php?album_artist=$matches[1]&discography=yes&albums=$matches[2]’, ‘top’ ); //songs rewrite rule add_rewrite_rule( ‘artists/([^/]+)/discography/([^/]+)/([^/]+)/?$’, ‘index.php?album_artist=$matches[1]&discography=yes&albums=$matches[2]&songs=$matches[3]’, ‘top’ ); } add_action(‘init’,’ex_rewrite_rules’); //Function to register query vars function ex_prefix_artists_query_var($vars){ $vars[] = ‘discography’; $vars[] = ‘album_artist’; return $vars; } add_filter(‘query_vars’,’ex_prefix_artists_query_var’); //function to load template […]

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

I have a custom tag-search feature, which allows people to search multiple tags to return relevant posts. Say they want to see posts that are tagged both ‘WordPress’ and ‘Tutorials’. I’m using the template_include filter, like so: public static function template_redirect( $template ) { if( isset($_GET[‘tag-search’]) ) { $template = locate_template( array( ‘search.php’, ‘archive.php’, ‘index.php’ […]

Use template_include with custom post types

I want to check for an appropriate template in the theme folder before falling back to the file in my plugin directory. Here’s my code: add_filter(‘template_include’, ‘sermon_template_include’); function sermon_template_include($template) { if(get_query_var(‘post_type’) == ‘wpfc_sermon’) { if ( is_archive() || is_search() ) : if(file_exists(TEMPLATEDIR . ‘/archive-wpfc_sermon.php’)) return TEMPLATEDIR . ‘/archive-wpfc_sermon.php’; return dirname(__FILE__) . ‘/views/archive-wpfc_sermon.php’; else : if(file_exists(TEMPLATEDIR […]

Is there any way to use get_template_part() with folders?

I’m wondering if there is any way to use get_template_part() with folders? My main folder has a lot of files now because I put every re-usable element in a separate file. I’d like to put them in folders then. There is no information about that in Codex: http://codex.wordpress.org/Function_Reference/get_template_part

Methods of Integrating Plugin Data with Themes

I would like to get some opinions regarding the best practices for developing WordPress plugins that provide theme integration. In order to make sense as I ask this question, let me start with an hypothetical example of a scenario that I am curious about. Imagine that I create a plugin called “Discography”. Discography registers three […]