How to make a new function that includes a template

Add your share button html to a template file in your theme: your-theme/share-buttons.php <a href=”http://twitter.com/home/?status=<?php the_title(); ?> – <?php the_permalink(); ?>” target=”_blank” title=”Tweet this!”><img src=”http://localhost:8888/wordpress/wp-content/uploads/2016/10/social-twitter.png”></a> <a href=”http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&amp;t=<?php the_title(); ?>” target=”_blank” title=”Share on Facebook.”><img src=”http://localhost:8888/wordpress/wp-content/uploads/2016/10/social-facebook.png”></a> <a href=”http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo $url; ?>” target=”_blank”><img src=”http://localhost:8888/wordpress/wp-content/uploads/2016/10/social-pinterest.png”></a> <a href=”http://www.bloglovin.com/e/?b=’ .get_bloginfo(‘wpurl’) . ‘&#038;p=’ .get_permalink().’&#038;t=”.get_the_title().””onclick=\’window.open(this.href,&quot;bloglovin_like&quot;,&quot;height=320,width=480,toolbar=0,location=0,menubar=0,scrollbars=0,status=0&quot;); … Read more

Password protect a custom template

Post_password_required returns false in two cases: No password required Cookie with password present So, once you have entered the password and logged out, the cookie will still be present and you get access to the content. (When I go to your site, without login or password, I get the password field just as I should)

Give posts a particular template based on the assigned category

nikolaou, When I understand you question correct then you want to use different templates based on the categories you’re using within your posts, correct? If that’s the case, then you only need one template (single.php) and a combination of get_the_terms() and get_template_part(). <?php $categories = get_the_terms(get_the_ID(), ‘slug’); if ( in_array(‘cat1’, $categories) ) { get_template_part(‘partials/single’, ‘1’); … Read more

How to add custom meta box when you have a custom page template file

The front page configuration is a site option. You can know if the site is configured to display a page with get_option( ‘show_on_front’ ) and get the ID of the page with get_option( ‘page_on_front’ ). You could do something like this: add_action( ‘add_meta_boxes’, ‘cyb_add_metaboxes’, 10, 2 ); function cyb_add_metaboxes( $post_type, $post ) { if( $post->ID … Read more

Assign a template to a custom post type when displayed by the main loop on the home page

You are checking the source code of TwentySeventeen’s content.php selectively. The lines you quote are only about printing the publication time in case of a regular post. Directly below your lines the post/page title is printed regardless of post type. Regarding a) you don’t need to force anything, because as long as there is no … Read more

Assign Specific Template for Custom Post slug

Looking at the template hierarchy it does not look like there is a way to do this automatically, by post type and taxonomy. But, you could use a page template which you would need to select on every custom post where you want to use the different template. In the code where you define the … Read more

How can I get “Previous” and “Next” to show in the navigation besides the links?

You may like to use the_posts_pagination() instead of the_posts_navigation() or get_next/previous_posts_link(). The posts pagination function outputs a set of page numbers with links to the previous and next pages of posts. Example format would be like this below: <div class=”pagination_style”> <?php the_posts_pagination(array ( ‘prev_text’ => __( ‘PREV’ ), ‘next_text’ => __( ‘NEXT’ ), ‘screen_reader_text’ => … Read more