Set page template for all pages in wordpress with database update via functions.php

Set page template for all pages in wordpress with database update via functions.php add_action( ‘admin_init’, ‘set_page_templates’ ); function set_page_templates(){ $current_template = get_post_meta( $page->ID, ‘_wp_page_template’, true ); echo $current_template.’amit’; foreach( get_posts(‘post_type=page&posts_per_page=-1’) as $page ) { $current_template = get_post_meta( $page->ID, ‘_wp_page_template’, true ); $new_template = ‘yourtemplate.php’; if( $current_template != $new_template ) update_post_meta( $page->ID, ‘_wp_page_template’, $new_template ); } […]

How to override or change template forcefully for posts with functions.php?

add_action( ‘admin_init’, ‘set_page_templates’ ); function set_page_templates(){ $current_template = get_post_meta( $page->ID, ‘_wp_page_template’, true ); echo $current_template.’amit’; foreach( get_posts(‘post_type=post&posts_per_page=-1’) as $page ) { $current_template = get_post_meta( $page->ID, ‘_wp_page_template’, true ); $new_template = ‘yourpage-template.php’; if( $current_template != $new_template ) update_post_meta( $page->ID, ‘_wp_page_template’, $new_template ); } }

How to build a WordPress Post Pagination without plugin?

The function Paste this function code in your theme functions.php file: if ( ! function_exists( ‘post_pagination’ ) ) : function post_pagination() { global $wp_query; $pager = 999999999; // need an unlikely integer echo paginate_links( array( ‘base’ => str_replace( $pager, ‘%#%’, esc_url( get_pagenum_link( $pager ) ) ), ‘format’ => ‘?paged=%#%’, ‘current’ => max( 1, get_query_var(‘paged’) ), […]

How to add menu page with different name for first submenu item in wordpress?

You can make the ‘slug’ for the submenu page equal that of the top level page, and they’ll point to the same place: add_action(‘admin_menu’, ‘my_menu_pages’); function my_menu_pages(){ add_menu_page(‘My Page Title’, ‘My Menu Title’, ‘manage_options’, ‘my-menu’, ‘my_menu_output’ ); add_submenu_page(‘my-menu’, ‘Submenu Page Title’, ‘Whatever You Want’, ‘manage_options’, ‘my-menu’ ); add_submenu_page(‘my-menu’, ‘Submenu Page Title2’, ‘Whatever You Want2’, ‘manage_options’, […]

How to create custom widgets in WordPress?

Creating a Custom Widget in WordPress You can also paste the below code in your theme‚Äôs functions.php file. However, it will only be available when that particular theme is active. // Register and load the widget function wpb_load_widget() { register_widget( ‘wpb_widget’ ); } add_action( ‘widgets_init’, ‘wpb_load_widget’ ); // Creating the widget class wpb_widget extends WP_Widget […]

How to remove srcset in wordpress : Logo Problem | Images Problem

// Clean the up the image from wp_get_attachment_image() add_filter( ‘wp_get_attachment_image_attributes’, function( $attr ) { if( isset( $attr[‘sizes’] ) ) unset( $attr[‘sizes’] ); if( isset( $attr[‘srcset’] ) ) unset( $attr[‘srcset’] ); return $attr; }, PHP_INT_MAX ); // Override the calculated image sizes add_filter( ‘wp_calculate_image_sizes’, ‘__return_empty_array’, PHP_INT_MAX ); // Override the calculated image sources add_filter( ‘wp_calculate_image_srcset’, ‘__return_empty_array’, […]

How do I disable responsive images in WP 4.4?

// Clean the up the image from wp_get_attachment_image() add_filter( ‘wp_get_attachment_image_attributes’, function( $attr ) { if( isset( $attr[‘sizes’] ) ) unset( $attr[‘sizes’] ); if( isset( $attr[‘srcset’] ) ) unset( $attr[‘srcset’] ); return $attr; }, PHP_INT_MAX ); // Override the calculated image sizes add_filter( ‘wp_calculate_image_sizes’, ‘__return_empty_array’, PHP_INT_MAX ); // Override the calculated image sources add_filter( ‘wp_calculate_image_srcset’, ‘__return_empty_array’, […]

How to make a custom widget area in wordpress?

custom widget area in wordpress custom widget area in wordpress WordPress Amitpal Singh First of all place this code in function.php file to register a widget. Make sure that this widget name is unique and different for each. [php] if (function_exists(‘register_sidebar’)) { register_sidebar(array( ‘name’ => ‘Extra Widgets’, ‘id’ => ‘extra-widgets’, ‘description’ => ‘The extra widgets […]

Bitnami