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 );

 

Posted in wordpress | 1 Comment

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 );
?>

 

Posted in wphtml | 2 Comments

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 />';

?>

 

Posted in php | Leave a comment

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;
}
?>

 

Posted in wordpress | Tagged | Leave a comment

Remove taxonomy slug from url

you can add below plugin to remoe taxonomy name from term url link.

wp-no-taxonomy-base-url

Posted in wordpress | Tagged | Leave a comment

Update the_excerpt word length

Using given code you can increase or decrease wordpress default function length.

the_excerpt()

you can just coppy and past below code in function.php file and update text length using update return value.

function wordpresshtml_length( $length ) {
    return 20;
}
add_filter( 'excerpt_length', 'wordpresshtml_length', 999 );

 

Posted in wordpress | Tagged , | Leave a comment

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;
    }
}

 

Posted in wordpress | Tagged | Leave a comment

Fatal error: Cannot redeclare get_file_description() (previously declared in /home

Hello every one.
My issue is i have make one clone of sub domain form my site with staging but when i have run staging site i have getting below error.

Fatal error: Cannot redeclare get_file_description() (previously declared in /home

I have follow below steps: Upload all care file exclude of(wp-config.php,htaccess,and wp-content directory)

Check every file have not any static live url define in my site.

also rename sub domain with new sub domain and move all file there but cant solve.

Please give me a proper guide for solve this issue.

Posted in wphtml | 1 Comment

PHP 7 added new features

  • Speed : Php 7 add speed as compare to 5 and 6 it is twise to double speed execution.
  • Type Declarations : with php 7 you can declare variable type in function like object, array , float or int.
  • Error Handling : it will update with fatal error and exception handling.
  • New Operators : with php 7 added new operator call “Spaceship Operator”
  • Easy User-land CSPRNG : API for an easy to use and reliable Cryptographically Secure PseudoRandom Number Generator in PHP 7
    You cane generate random no with new function like( random_bytes(3) , random_int(1,15); ).

    unicode support for emoji

    echo “u{1F60D}”; // outputs 😍

Posted in wphtml | Leave a comment

wordpress 4.7.3 version for security

You can see mor update on wp site.
it will support follow 6 task.

  • Cross-site scripting (XSS) via media file metadata.
  • Control characters can trick redirect URL validation.
  • Unintended files can be deleted by administrators using the plugin deletion functionality.
  • Cross-site scripting (XSS) via video URL in YouTube embeds.
  • Cross-site scripting (XSS) via taxonomy term names.
  • Cross-site request forgery (CSRF) in Press This leading to excessive use of server resources.

DOWNLOAD wp 4.7.3 here

WordPress 4.7.3 Security and Maintenance Release

Posted in wordpress | Comments Off on wordpress 4.7.3 version for security