Articles of templates

style sheet header on Page Templates

What is the reason for using a style sheet header on page templates, where critcal values are assigned within a comments block in php, instead of just declaring constants, objects, or some other php structure? The style sheet header is like this: /* Theme Name: Twenty Fifteen Child Theme URI: * Description: Twenty Fifteen Child […]

How to get the HTML until </head>?

I’m coding a plugin that adds a filter to single_template. The filter function successfully returns the path to my show-post-in-a-lightbox.php template. As you can guess from its name, my template is intended to show a single post in a lightbox. Therefore I need to show only the post content and avoid the title bar, menus, […]

Custom page type – template under page attributes?

I thought we can apply templates to custom page types: You can’t apply templates to custom post types in this manner. That will show up only if the post type is ‘page’ My code: function keyword_pages_init() { $args = array( ‘label’ => ‘Keywords’, ‘public’ => true, ‘show_ui’ => true, ‘capability_type’ => ‘page’, ‘hierarchical’ => false, […]

Proper way to use get_the_content() in front-page.php and the content-home.php?

<div class=”class1″> <ul> <li> <div class=”class2″> <?php the_post_thumbnail( ‘large’) ?> </div> <div class=”class3″> <a href=””>category</a> <h2><?php the_title(); ?></h2> <p><?php echo wp_trim_words( get_the_content(), 70 ); ?> </p> </div> </li> </ul> </div> The above is an excerpt that is kept on content-home.php This is the correct version or correct coding practice → <p><?php echo wp_trim_words( get_the_content(), 70 […]

How to remove wp_link_pages() from template

The code in the answer of this thread works fine, but one part I don’t understand: Remove wp_link_pages() from the template Where is the exact code to remove? I looked into /wp-includes/post-template.php, but removing it there produces an error. At the moment, with using the code: add_filter( ‘the_content’, function( $content ) { return $content . […]

Add class or ID to any WordPress function

I often find the need to add class or ID’s to WordPress functions. Preferably I would like to do this in the a template (not in functions.php). Example: <?php the_excerpt(); ?> Will output the excerpt inside <p>. How can I add a class to the paragraph so that I get <p class=”something”>The excerpt text…</p>

How to create function from code?

Can anyone tell me how to create a function out of the following code? It’s for displaying page navigation links in a custom category template. As you can see, it’s quite a large block of code and I would like to wrap it in a function so I can generate the links with just a […]

Different template for posts of all subcategories of category

I want to use different template for posts of all subcategory of one category. Below is the Code I am using : add_filter( ‘single_template’, ‘get_custom_cat_template’ ) ; function get_custom_cat_template( $single_template ) { global $post; if ( is_category( ‘blog’ ) || in_category( ‘blog’ ) ) { $single_template = dirname( __FILE__ ) . ‘/single-blog.php’; } return $single_template; […]

When a link doesn't exist, how to tell WordPress what to do? (404 Error Page)

If you click any link that doesn’t exist in my main site site, for example this link, i expect the WordPress to use the default index.php file that has this loop inside it: <div class=”main col <?php post_class(); ?>”> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $post_id = […]

Use another author.php if different multisite subsite?

I have a multisite installation with 2 subsites (site A, site B) using same theme. Is it possible to use a different author.php if Im on the site B? Assuming the second author template exists. For exeample.. if (blog_id == 2){ // use this template diff-author-template.php } else { //use this author.php} Thanks