Search
 
SCRIPT & CODE EXAMPLE
 

PHP

workpress change page title from shortcode

add_filter( 'pre_get_document_title', function( $title ) {
    global $post;
    if ( ! $post || ! $post->post_content ) {
        return $title;
    }
    if ( preg_match( '#[mc_set_title.*]#', $post->post_content, $matches ) !== 1 ) {
        return '';
    }
    return do_shortcode( $matches[0] );
} );

add_shortcode( 'mc_set_title', function( $atts ) {
    if ( ! doing_filter( 'pre_get_document_title' ) ) {
        # just remove the shortcode from post content in normal shortcode processing
        return '';
    }
    # in filter 'pre_get_document_title' - you can use $atts and global $post to compute the title
    return 'MC TITLE';
} );
Comment

PREVIOUS NEXT
Code Example
Php :: laravel make api resource 
Php :: install php7 
Php :: foreach loop in php stack overflow 
Php :: while in php 
Php :: set border phpoffice phpexcel 
Php :: wp add_action 
Php :: Csv To AssoT Php 
Php :: curl failed laravel centos 
Php :: tenary php 
Php :: laravel check model column was changed 
Php :: wordpress shortcode api 
Php :: include JS or Css in wordpress plugin 
Php :: numbers not displaying in laravel pagination 
Php :: check the existing image in s3 laravel 
Php :: what are the different types of PHP variables? 
Php :: delete record without a page refresh with ajax in php 
Php :: php throw fatal error 
Php :: laravel link to css or image 
Php :: magento check which user has added a product 
Php :: Call to undefined method IlluminateDatabaseEloquentRelationsHasMany::attach() 
Php :: laravel set env to production 
Php :: php array_diff_assoc 
Php :: laravel project composer [ErrorException] Undefined index: name 
Php :: php remove directory only if empty 
Php :: laravel 8 logout 419 page expired 
Php :: twig url 
Php :: php echo statement 
Php :: preg_match in php 
Php :: Alternatives to chmod 775 or 664 
Php :: cookie phpsessid will be soon treated as cross-site cookie against 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =