رفتن به مطلب

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


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

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

بعنوان مثال کد زیر رو اگه توی 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] عنوان رو نشون میده.

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...