Add date before entry title in Twenty Twelve

Base on @Tunji answer. You can add some conditions to the function to detect home-page, feeds… function display_extra_title( $title, $id = null ) { $date = the_date(”, ”, ”, false); if(is_home()){ $title = get_bloginfo( ‘name’ ); return $date . $title; } else{ return $date . $title; } } add_filter( ‘the_title’, ‘display_extra_title’, 10, 2 ); In … Read more

Find out last 7 days of upload images, last week uploaded image from Gallery and display them in different pages

Here I’ve written a function for you- function the_dramatist_get_post_by_time_range( $args=”” ) { $date_query = array(); if ( $args === ‘last 7 days’) { $date_query = array( ‘after’ => ‘1 week ago’ ); } else { $month_ini = new DateTime(“first day of last month”); $month_end = new DateTime(“last day of last month”); $date_query = array( array( … Read more

get db values for external js file

You need to use wp_localize_script() when you enqueue the js script. It’s usually a good alternative of ajax way and this will save you to create multiple js files. wp_localize_script() can be used to make any data available to your script that you can normally only get from the server side of WordPress. As you … Read more

How do I access post_meta key with php?

According to docs (https://developer.wordpress.org/reference/functions/get_post_meta/), it should be something like: <?php if(!get_post_meta(get_the_ID(), ‘buy_status’, true)): ?> display: block; <?php else: ?> display: none; <?php endif; ?>

Querying a custom post type, but not show duplicates

Ahh iv figured out a way to do this: <?php $args = array( ‘post_type’ => ‘classes’, ‘orderby’ => ‘title’, ‘posts_per_page’ => -1 ); $the_query = new WP_Query( $args ); $unique_titles = array(); if( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $title = get_the_title(); if( ! in_array( $title, $unique_cities ) ) : $unique_titles[] = … Read more

Else/If Statement to Display Photo Descriptions

How about like this: <div style=”position: relative”> <?php the_post_thumbnail(‘large’); $imagedesc = get_post(get_post_thumbnail_id())->post_content; if(!empty($imagedesc)) { echo ‘<span style=”position:absolute; bottom:9px; right:0; color:#FFF; background:rgba(0,0,0,0.8); padding:4px 6px; font-size:0.7em”>’; echo $imagedesc; echo ‘</span>’; } ?> </div>

How to hide the author box of a specific user?

If you know the data of the author, you can wrap that box with an if and the function get_the_author if( get_the_author() == “name_of_the_author” ){ // Don’t do it }else{ // Print box } EDIT with the final answer updated: <?php echo $td_mod_single->get_social_sharing_bottom();?> <?php echo $td_mod_single->get_next_prev_posts();?> <?php $user = get_user_by(“login”, “pknn”); // user object // … Read more

I want to generate the pdf and save it in library?

Saving in WordPress library can be done by using this function media_handle_upload. PDF can be created in many ways. The best method depends on your runtime enviroment and the functionality you are looking for. There are several PDF generating libs for PHP out there, for example PDFlib. But again your question is far broad.

post_content is stripping HTML when adding a new post? [closed]

When WP inserts a post one of the things it does is check both the current user’s capabilities, and which html tags are allowed to be used. There are two ways to modify this: Method 1: wp_kses_allowed_html hook You can modify the allowed set of html tags, given a context, by using this filter: https://codex.wordpress.org/Function_Reference/wp_kses_allowed_html … Read more