Hide comment on media attachment page

Add Below code in function.php

function filter_media_comment_rpl( $open, $postidn ) {
    $post = get_post( $postidn );
    if( $post->post_type == 'attachment' ) {
        return false;
    }
    return $open;
}
add_filter( 'comments_open', 'filter_media_comment_rpl', 10 , 2 );

 

Advertisements

Post url with blog

Add Blog Post with url pree fix blog

Example :
Default : http://www.wordpresshtml.com/post-url-blog/
Update : http://www.wordpresshtml.com/blog/post-url-blog/

You can just copy give code in your function.php and update permalink.

<?php
function create_new_url_querystring() {
    add_rewrite_rule(
        'blog/([^/]*)$',
        'index.php?name=$matches[1]',
        'top'
    );
	
    add_rewrite_tag('%blog%','([^/]*)');
}

add_action('init', 'create_new_url_querystring', 999 );


function append_query_string( $url, $post, $leavename ) {
 if ( $post->post_type == 'post' ) {  
  $url = home_url( user_trailingslashit( "blog/$post->post_name" ) );
 }
 return $url;
}
add_filter( 'post_link', 'append_query_string', 10, 3 );
?>

 

Send Grid to email send

Just copy give code and set api key in “testmail.php” file and cal “testmail.php” file in your browse url

You can sennd you email using sandgrid-php and add below code into your php file to use below code.

 

<?php
// If you are using Composer
require 'sendgrid-php.php';
$from = new SendGridEmail("Example User", "info@wordpresshtml.com");
$subject = "Sending with wordpress html";
$to = new SendGridEmail("Example User", "test@gmail.com");
$content = new SendGridContent("text/plain", "and easy to do anywhere, even with PHP http://www.wordpresshtml.com ");
$mail = new SendGridMail($from, $subject, $to, $content);

$apiKey = 'apikey ad_here';
$sg = new SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode() . '<br />';
echo $response->headers() . '<br />';
echo $response->body() . '<br />';

?>

 

Remove post type slug from url and replace with terms

Copy below code in your function.php file.

Create post type with url taxonomy term

“our_homes” taxonomy terms and  “property” Post type.
you must be assign category else it will error

 

<?php 
add_action('init', 'wr_property');

function wr_property() {

     register_taxonomy(
        'our_homes',
        'property',
        array(
            'label' => 'Taxonomy',
            'singular_label' => 'taxonomy',
            'hierarchical' => true,
            'query_var' => true,
            'rewrite' => array('slug' => 'taxonomyname'),
        )
    );

    $labels = array(
        'name' => _x('Property', 'post type general name'),
        'singular_name' => _x('Property', 'post type singular name')
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail', 'excerpt'),
        'rewrite' => array(
            //'slug' => 'event',
            'slug' => '/%our_homes%',
            'with_front' => false    //this is must be false for hide post type slug in url
        ),
        'has_archive' => 'property'
    ); 

    register_post_type( 'property' , $args );
    flush_rewrite_rules();
}
if($_POST)
{
add_action('save_post', 'save_details'); //create custom post type
}


// use this code for taxomy remove from url in custom post yep    // in post type set 'with_front' => false
add_filter('post_type_link', 'property_permalink_structure', 10, 4);
function property_permalink_structure($post_link, $post, $leavename, $sample)
{
	
	 $our_homes_term = get_the_terms( $post->ID, 'our_homes' );   //our_homes taxonomy term
	 if($our_homes_term)
		{
	      if ( false !== strpos( $post_link, '%our_homes%' ) ) {
			   	$post_link = str_replace( '%our_homes%', array_pop( $our_homes_term )->slug, $post_link );
				
			}
	
	  }
    return $post_link;
}
?>

 

Wp to add custom field display in admin post list

You can add any custom field in your admin post type / page / custom post type list using below code.

Below code example for display event start date in event post type admin list.

here in below example “event” is custom post type and “event_date_start” is custom field.

add_filter('manage_event_posts_columns', 'hs_event_table_head');
function hs_event_table_head( $columns ) {
    $columns['event_date_start']  = '&lt;sapn&gt;Start Date&lt;/sapn&gt;';
    return $columns;

}
add_action( 'manage_event_posts_custom_column', 'hs_event_table_content', 10, 2 );

function hs_event_table_content( $column_name, $post_id ) {
    if( $column_name == 'event_date_start' ) {
        $featured_product = get_post_meta( $post_id, 'event_date_start', true );
        echo $featured_product;
    }
}