Filter Hook Trong Wordpress

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Replace 1 chui trong cc post

Filter the_content c cung cp sn trong wordpress. Ta ch cn gi ra bng


add_filter();. Trong v d vn di ch hoclamweb hoclamweb

<pre class="lang:default decode:true">


function hoclamweb_rplace($content){
$find = 'hoclamweb';
$rplace = '<i>hoclamweb</i>';
$content = str_replace( $find, $rplace, $content );
return $content;
}
add_filter('the_content','hoclamweb_rplace');
</pre>

ch : nu vit nh th ny function hoclamweb_rplace() {} (khng c $content) th s


khng chy c.

Edit url khi click vo author link


Mc nh wordpress s chuyn ti mc archive ca author khi click vo author
trong post. Tuy nhin ta c th vit li tr url n 1 trang bt k nh bn di.
<pre class="lang:default decode:true">
function my_multi_author_link($url) {
$url = 'http://localhost:8080/wordpress/2016/09/23/about-author-page/';
return $url;
}
add_filter( 'author_link', 'my_multi_author_link', 10, 1 );
</pre>

T to 1 custom post type

Gi s bn mun vit bi v du lch chn hn, Nhng gi bn khng mun dung ci Posts
c sn ca wordpress m bn mun vit 1 ci mi c tn l 'Time Travelers' chng hn
tnh nng ging ht nh Posts ca wordpress !!!!! Bn c th iu chnh dashboard ca
wordpress bng cch gi hook nh bn di
Chng ta c th to 1 custom post nh bn di theo 3 bc c bn
+ vit 1 function : trong function ny s tr v 1 event no (nh vi d bn di l tr
v register_post_type( 'time_traveler', $args );
+ b ci event ny vo hook bng lnh add_action(name hook,function name) : v d
di l add_action( 'init', 'tutsplus_register_post_type' );

<pre class="lang:default decode:true">


add_action( 'init', 'tutsplus_register_post_type' );
function tutsplus_register_post_type() {
$args = array(
'label' => 'Time Travelers',
'labels' => array(
'name'

=> 'Time Travelers',

'singular_name' => 'Time Traveler',


'add_new_item' => 'Add New Traveler',
'edit_item'

=> 'Edit Traveler',

'new_item'

=> 'New Traveler',

'view_item'

=> 'View Traveler',

'search_items' => 'Search Travelers',


'not_found'
),

=> 'No Travelers',

'description' => 'A post type used to provide information on Time Travelers.',
'public'

=> true,S

'show_ui'

=> true,

'supports'

=> array(

'title',
'editor',
'excerpt',
),
);
register_post_type( 'time_traveler', $args );
}
</pre>

https://code.tutsplus.com/tutorials/adding-custom-hooks-in-wordpress-custom-actions-cms-26454

vt_pipeline.v

vt_pipeline.v

You might also like