رفتن به مطلب

درج عنوان نوشته یا برگه در متن نوشته یا برگه


پست های پیشنهاد شده

میتونید از شورتکد ها استفاده کنید

بعنوان مثال کد زیر رو اگه توی functions.php قرار بدید یه شرتکد میسازه به اسم "[my-title]"

<?php
/**
 * Title shortcode
 *
*/

class my_title_shortcode{
	/**
	 * $shortcode_tag 
	 * holds the name of the shortcode tag
	 * @var string
	 */
	public $shortcode_tag = 'my-title';

	/**
	 * __construct 
	 * class constructor will set the needed filter and action hooks
	 * 
	 * @param array $args 
	 */
	function __construct($args = array()){
		//add shortcode
		add_shortcode( $this->shortcode_tag, array( $this, 'shortcode_handler' ) );
	}
	
	/**
	 * shortcode_handler
	 * @param  array  $atts shortcode attributes
	 * @param  string $content shortcode content
	 * @return string
	 */
	function shortcode_handler( $atts, $content = null ) {
		// Attributes
		extract( shortcode_atts(
			array(
				'id' => '',
			), $atts )
		);
		
		if( ! $id ) {
			global $post;
			$id = $post->ID;
		}
		
		$output = '';
		
		$output = apply_filters( 'the_title', get_post( $id )->post_title );
		
		return $output;
	}
}

new my_title_shortcode();

 

و هرجای متن که بنویسید [my-title] عنوان رو نشون میده.

  • امتیاز 1
لینک به ارسال

لطفا برای ارسال دیدگاه وارد شوید

شما بعد از اینکه وارد حساب کاربری خود شدید می توانید دیدگاهی ارسال کنید



ورود به حساب کاربری
×
×
  • اضافه کردن...