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

WP Customizer API loaded into functions.php

Yes. You can load the code in the customize_register action. One example: <?php // File: functions.php add_action( ‘customize_register’, function( $wp_customize ) { require_once dirname( __FILE__ ) . ‘/inc/customize.php’; wpse256532_customize_register( $wp_customize ); } ); And the inc/customize.php file: <?php // File: customize.php function wpse256532_customize_register( $wp_customize ) { $wp_customize->add_setting( /* … */ ); $wp_customize->add_control( /* … */ … Read more

Custom Post type content within a slider

Since WP loaded with jQuery by default, you might be able to modify this script http://www.jqueryscript.net/rotator/Simple-Text-Slider-Rotator-with-jQuery-CSS.html to create a testimonials sliders. For randomizing your query, just put ‘orderby’ => ‘rand’ in your $args variable like this: $args = array( ‘post_type’ => ‘testimonials’, ‘orderby’ => ‘rand’); There are way more arguments you can learn from here: … Read more

Is There A WordPress Hook for Accessing Attachments for A Particular Page?

Here’s one way, out of many, where we use the the_content filter and loop through the get_attached_media( $type ) to construct the list of attached media. We can e.g. use $type=”image” for images or $type = null for all mime types. add_filter( ‘the_content’, function( $content ) { // Nothing to do – target single posts … Read more

Customizer: get_preview_url() inside customize_save_after hook

I managed to do it via JS, it does exactly the same thing at the time I want it to: wp.customize.bind( ‘saved’, function( d ){ $.ajax({ url: ajaxurl, type: ‘post’, dataType: ‘json’, data: { action: ‘actionName’, url: wp.customize.previewer.previewUrl() } }); }); I can then use the preview URL in an ajax action function. Don’t forget … 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