• <?php
    /*
    Plugin Name: Auto Generate Title
    Author: Jatinder Pal Singh, Themummichogblog.com
    Version: 1.2
    Tags: post title, title, automatic, generator
    Requires at least: 3.0.1
    Tested up to: 5.4.2
    Stable tag: 1.1
    License: GPLv2 or later
    License URI: https://www.gnu.org/licenses/gpl-2.0.html
    Description: Auto Generate Title from the POST Content. If you leave Title blank, it will use the text written in [agt][/agt] within your post content. If you do not mention these shortcodes in your post, It will pick up first 30 characters from the post.

    Changes:
    1) $postdata2 = preg_replace(“/[^A-Za-z0-9 ]/”, ”, $postdata);
    2) $data[‘post_title’] = substr($postdata2,0,30);

    */

    add_shortcode(“agt”, “agt_shortcode”);
    function agt_shortcode( $atts, $content = null ) {
    return $content;
    }

    add_filter( ‘wp_insert_post_data’ , ‘auto_generate_title’ , ’99’, 2 );
    function auto_generate_title( $data , $postarr )
    {

    $title_of_post = ltrim($data[‘post_title’]);
    $length_of_title = strlen($title_of_post);
    $postdata = ltrim($data[‘post_content’]);
    //$postdata2 = preg_replace(“/[^A-Za-z0-9 ]/”, ”, $postdata);
    $postdata2 = preg_replace (‘/[^\p{L}\p{N}]/u’, ‘ ‘, $postdata);
    if($length_of_title<1)
    {
    $matchPattern = “/\[agt\](.*?)\[\/agt\]/”;
    preg_match_all($matchPattern, $postdata, $foundIt, PREG_PATTERN_ORDER);
    if (isset($foundIt[1][0]))
    $data[‘post_title’] = $foundIt[1][0];
    else
    $data[‘post_title’] = substr($postdata2,0,30);
    }
    return $data;
    }
    ?>

  • The topic ‘Vwrsion 1.2.1’ is closed to new replies.