Tag Info

Hot answers tagged

3

The answer is eager loading or cache or both. Eager loading Have a look to this pseudo-code: $ids = get_ids_from_a_db_table(); foreach ( $ids as $id ) { $row = get_row_from_foreign_table_using( $id ); echo "Row title for the ID: $id is $row->title"; } If the number of $ids is n than this simple code runs n+1 queries, the first to load the ids, ...


3

Use a use statement: add_filter( 'single_template', function ( $template ) use ( $name ) { Or just pass all templates at once, and create just one function: add_filter( 'single_template', function ( $file ) use ( $templates ) { global $post; if ( in_array ( $post->post_type, $templates ) ) return __DIR__ . ...


3

Yes, this is the intended behaviour: page-{slug}.php - If the page slug is recent-news, WordPress will look to use page-recent-news.php So, simply use a different filename for your templates, like template-contact.php for example. You can find more info about this here: https://codex.wordpress.org/Template_Hierarchy


2

Your code doesn't really do any "user logged in" check, and you aren't using a couple of the globals you import. function restrict_access_to_unlogged_users($template) { if (!is_user_logged_in()) { $template = get_stylesheet_directory() . '/need-login.php'; } return $template; } add_filter( 'page_template', 'restrict_access_to_unlogged_users', 20 ...


2

What you want to do is impossible without a page.php type of template. There is no template hierarchy that support what you want to achieve. It works exactly the same with categories. taxonomy-categorycourses.php will not display a list of categorycourses, so would category-categorycourses.php if categorycourses was a normal category. If you click on ...


2

Parsing shortcodes from strings WordPress parses and replaces shortcodes from a piece of content via the do_shortcode function. This function, in turn, calls get_shortcode_regex, which returns the regular expression for matching shortcodes in a string. Using this function, we can get a list of all shortcodes ourselves: $pattern = get_shortcode_regex(); ...


1

You need to properly enqueue your script. You should hook your script to the function enqueue_custom_script() { wp_register_script('myJW', get_bloginfo('template_url') . '/jwplayer.js'); wp_enqueue_script('myJW'); } add_action( 'wp_enqueue_scripts', 'enqueue_custom_script' );


1

There are a lot of ays to do the trick, one possible is use a function that use a static variable. However, before you can be able to get the arguments set in shortcode, the shortcode must be processed... function foobar_func( $atts = array(), $out = FALSE ){ static $args = array( 'foo' => 'default foo', 'bar' => 'default bar' ); ...


1

It is quite difficult to understand what you have done. One of my concerns is using get_the_post_thumbnail() and catch_that_image() together in the same code as you have done. I have knowledge of catch_that_image() function and have used it before. It is a nice-to-know-function that is usually used by coders to retrieve the first image to display it in the ...



Only top voted, non community-wiki answers of a minimum length are eligible