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 get Images included in Post

You can use get_posts() (Codex ref for getting Post attachments). <?php $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post->ID ); $attached_images = get_posts( $args ); ?>

How to override admin-bar style

You can override admin-bar with this function, don’t need to mess with admin-bar.css. Steps: Write your css Put inside the function (given below) Add this inside functions.php // customize admin bar css function override_admin_bar_css() { if ( is_admin_bar_showing() ) { ?> <style type=”text/css”> /* add your style here */ </style> <?php } } // on … Read more

Get page IDs based on which template they are using?

WP_Query goes only through posts by default. Try adding page as your post type: $the_query = new WP_Query(array( ‘post_type’ => ‘page’, /* overrides default ‘post’ */ ‘meta_key’ => ‘_wp_page_template’, ‘meta_value’ => ‘templates/_partner.php’ )); See: WP_Query – Type Parameters

Show Woocommerce minicart widget in checkout page sidebar? And, how to make this update secure by overriding widget?

The cart widget isn’t showing because it’s configured to not show on the cart and checkout page. If you want to change that take a look at class-wc-widget-cart.php, there you find the following line: if ( is_cart() || is_checkout() ) return; Change it to: if ( is_cart() ) return; To show the widget on the … Read more

Template for specific post of custom post type

For the templates WordPress uses, please always refer to Template hierarchy scheme in the Codex. As you can see there, single-{$posttype}-{$slug}.php does not exist, there is only single-{$posttype}.php. To do what you want, have a look at the filter ‘single_template’: add_filter( ‘single_template’, function( $template ) { global $post; if ( $post->post_type === ‘event’ ) { … Read more

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”;

How to customize the default HTML for WordPress Attachments

I want to change the default HTML code structure so that I can insert additional tags Run a filter on img_caption_shortcode, you can find that hook in the source here. http://core.trac.wordpress.org/browser/tags/3.0.1/wp-includes/media.php#L720 Example add_filter( ‘img_caption_shortcode’, ‘my_caption_html’, 10, 3 ); function my_caption_html( $current_html, $attr, $content ) { extract(shortcode_atts(array( ‘id’ => ”, ‘align’ => ‘alignnone’, ‘width’ => ”, … Read more

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