How to remove text and retain in caption image using the_content function

If you are trying to remove the text i think the below code is what is adding this /// this is where your content is being inserted <div class=”strip_first_image”> <?php $content = get_the_content();$content = preg_replace(“/<img[^>]+\>/i”, ” “, $content); $content = preg_replace(“/\[caption.*\[\/caption\]/”, ”, $content);$content = apply_filters(‘the_content’, $content);$content = str_replace(‘]]>’, ‘]]>’, $content);echo $content; ?> </div> Someone with … Read more

Add div before the first paragraph the_content [closed]

Yogenisia’s is right that you should use the_content filter. If you want to insert something before the first paragraph, locate the first <p> in $content, then insert your div with substr_replace. add_filter( ‘the_content’, ‘namespace_insert_before_first_paragraph’ ); function namespace_insert_before_first_paragraph( $content ) { $my_div = ‘<div> … </div>’; $first_para_pos = strpos( $content, ‘<p’ ); $new_content = substr_replace( $content, … Read more

Need to know custom code to display random and most viewed posts in wordpress posts and pages

A standard WordPress install doesn’t keep track of visits to pages/posts. So without a plugin there’s no way to know which posts/pages are visited most often. As to finding random posts that’s as simple as: $args = array( ‘post_type’ => array( ‘post’, ‘page’, ‘my-custom-post-type’ ) ‘orderby’ => ‘rand’, ); $query = new WP_Query ($args);

How to get the latest URL of my blog?

easy to do with get_posts // search the last post $posts = get_posts([ “posts_per_page” => 1, ]); foreach ($posts as $p) { // display the permalink echo esc_html(get_permalink($p)); } documentation of get_posts : https://codex.wordpress.org/Function_Reference/get_posts

Custom wordpress loop

You can set your custom loop something like this $a=2; //In while loop counter increments by one $counter++ if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); if($a%3!=0){ //Here write function to display title and discription ?> <div class=”col-md-4 col-sm-6″> <div class=”cp-attorneys-style-2″> <div class=”frame”> <a href=”https://wordpress.stackexchange.com/questions/263067/<?php the_permalink(); ?>”><?php the_post_thumbnail(”); ?></a> <div class=”caption”> <div class=”holder”> <ul> … Read more

How to add new post using a form to categories when categories are using as menu

The post_category parameter has to be an array, try this: $post = array(‘post_type’=>’post’, ‘post_author’=>$author, ‘post_status’=>’publish’, ‘post_title’ => ‘Test Title’, ‘post_category’ => array(‘679′) ); Ref: http://codex.wordpress.org/Function_Reference/wp_insert_post#Parameters If that doesn’t work for you, try using category_name: ‘category_name’ => ‘category_name’,

Custom Fields for Author Box

Add the new custom field to the author profile function my_epl_custom_user_contact( $contactmethods ) { $contactmethods[‘custom’] = __( ‘Custom’, ‘easy-property-listings’ ); return $contactmethods; } add_filter (‘user_contactmethods’,’my_epl_custom_user_contact’,10,1); Create the HTML output of the Custom Fields function my_epl_get_custom_author_html($html=””) { global $epl_author; if ( $epl_author->custom != ” ) { $html=” <a class=”epl-author-icon author-icon custom-icon-24″ href=”http://custom.com/” . $epl_author->custom . ‘” … Read more