Fatal error: Cannot redeclare function

This is the example code to fix the fatal error and redirect user as per the given page id. You can further optimise the code, if the redirection is going to remain same for “DE” and “US” for all the pages, you can just skip the if ( is_page( 90 ) ) check for these … Read more

Admin-ajax php not working on new wordpress version

I previously thought that the issue was ajax/javascript related but it only seemed that way because the ajax script was not receiving any data. After inspection I saw that my query was returning 0 values. It turned out to be an issue of wp_queries breaking when using meta_query combined with the repeater format of Advanced … Read more

Best Way to Change a String in a WordPress Post

You can create a new shortcode with this code add_shortcode(“currentDay”, function ($attr, $content, $tag) { $date = current_time(“Y-m-d”); return $date; }); and you just have to put [currentDay] in the content

How run a non-WordPress PHP Program on a WordPress site?

Move WordPress from root folder into subdirectory and create a .htaccess file in root folder, and put this content inside (just change example.com and my_subdir): RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?example.com$ RewriteCond %{REQUEST_URI} !^/my_subdir/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /my_subdir/$1 RewriteCond %{HTTP_HOST} ^(www.)?example.com$ RewriteRule ^(/)?$ my_subdir/index.php [L] That’s all 🙂

Help Fallback (thumbnail)

This should work global $post; $html = “”; $my_latest_posts_widget = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3 )); $html .= ‘<div id=”container_recent_posts_widget” class=”container_recent_posts_widget”>’; if( $my_latest_posts_widget->have_posts() ) : while( $my_latest_posts_widget->have_posts() ) : $my_latest_posts_widget->the_post(); $thumb = get_template_directory_uri() .’/assets/images/default-image-post-thumbnail-widget.jpg’; if ( has_post_thumbnail() ) { //override fallback image if post has any thumbnail $thumb = get_the_post_thumbnail_url(); } … Read more

Fetching Initials of the Commentator in the WordPress Website

Here is function that return you the comment author initials by the comment id function get_comment_author_initials($comment_id) { $author = get_comment_author($comment_id); $words = explode(” “, $author); $initials = null; foreach ($words as $w) { $split = mb_str_split($w); // to cover unicode char $initials .= $split[0]; } return $initials; } function mb_str_split( $string ) { return preg_split(‘/(?<!^)(?!$)/u’, … Read more

How to suppress template-parts in undescores?

First of all a simple advice if you are a complete beginner: i suggest you start from scratch with a tutorial that step by step takes you to create a theme. That way you will have a better understanding on how it works. Underscores is great i use it my self but if you are … Read more

Remove slugs from custom posts type

if ( ! in_array( $post->post_type, array( ‘internal_doors’ ) ) || ‘publish’ != $post->post_status ) replace above with if ( ! in_array( $post->post_type, array( ‘internal_doors’,’custom post type name1′, ‘custom post type name2’ ) ) || ‘publish’ != $post->post_status ) and if ( ! empty( $query->query[‘name’] ) ) $query->set( ‘post_type’, array( ‘post’, ‘internal_doors’, ‘page’ ) ); replace … Read more

Customizer: How to change Header Image description

The description param unfortunately is not used in this control. You can see that the message is hard-coded in the control’s template. That should be changed in core, but in the mean time, you can enqueue some JS at the customize_controls_enqueue_scripts action with the dependency of customize-controls which does this: wp.customize.control( ‘header_image’, function( control ) … Read more