How to overwrite youtube embed?

Taking a closer look at the code provided on that site, it appears that the main differences with what it output by default by WordPress is the following: the iframe is wrapped with a div that has a class of embed-container there are CSS styles that are used by that class In WordPress, to wrap … Read more

How to get the post count for the last x days filtering by categories

function get_days_ago_post_count_by_categories($ids){ $date_query = array( array( ‘after’=>’4 days ago’, ‘inclusive’ => true, ) ); $args = array( ‘post_type’ => ‘post’, ‘post_status’=>’publish’, ‘category__in’ => (array)$ids, ‘date_query’ => $date_query, ‘no_found_rows’ => true, ‘suppress_filters’ => true, ‘fields’=>’ids’, ‘posts_per_page’=>-1, ‘orderby’ => ‘ID’ ); $query = new WP_Query( $args ); return $query->post_count; } Note: code isn’t tested and just to … Read more

How to get author ID when an author page is being viewed?

wp_loaded is too early, the request hasn’t been parsed yet – use the action wp instead (called at the end of WP::main(), once the request has been parsed and posts have been queried). To get the user object, just use $author = get_queried_object();

Walker class: Problems with understanding how walk() method can be called without error

Per comments, it’s called with call_user_func_array, so the 1st 2 elements get assigned to the declared arguments $elements and $max_depth, leaving the third element ($r which is the original $args) to be assigned via array_slice to $args. Eg function wpse172812( $elements, $max_depth ) { $args = array_slice(func_get_args(), 2); error_log(“elements=$elements, max_depth=$max_depth, args=” . print_r( $args, true … Read more

Dynamically change feature image in customiser

The customizer has a special control for file uploads. Assuming that you already know how the theme customizer works, you would have to add four controls in this fashion: $wp_customize->add_control( new WP_Customize_Upload_Control( $wp_customize, ‘wpse215632_image_1’, array( ‘label’ => __( ‘First image’, ‘wpse215632_theme’ ), ‘description’ => __( ‘More about first image’, ‘wpse215632_theme’ ), ‘section’ => ‘wpse215632__section_id’, ‘settings’ … Read more

Displaying post per day

This is quite basic but should help you on your way. //Get posts for the current week $args = array( ‘date_query’ => array( array( ‘year’ => date( ‘Y’ ), ‘week’ => date( ‘W’ ), ) ) ); //Check for search query if ( isset( $_GET[‘s’] ) ) { $args[‘s’] = $_GET[‘s’]; } //Create these variables … Read more

Check if widget has content

Problem solved by this code below: <?php if (is_active_sidebar(‘extra_widget_1’)) { ?> <li> <?php dynamic_sidebar(‘extra_widget_1’); ?> </li> <?php } ?>

WordPress customizer: load controls in a custom div

Put below codes in your functions.php function sorcey_customize_register($wp_customize){ $wp_customize->add_section(‘sorcey_footer’, array( ‘title’ => __(‘New Section’, ‘text_domain’), ‘description’ => ”, ‘priority’ => 120, )); /* ============================= Text input ===============================*/ $wp_customize->add_setting(“sr_copyright”, array( “default” => “”, ‘capability’ => ‘edit_theme_options’, “transport” => “postMessage”, )); $wp_customize->add_control(new WP_Customize_Control($wp_customize, “sr_copyright_ctrl”, array( “label” => __(“Title”, “text_domain”), “section” => “sorcey_footer”, “settings” => “sr_copyright”, “type” => … Read more