kisukedeath

Wordpress Hooks

Apr 29th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. Register a Custom Menu in the Admin
  2.  
  3. function register_my_custom_menu_page() {
  4.  add_menu_page( 'custom menu title', 'custom menu', 'manage_options', 'myplugin/myplugin-admin.php', '', 'dashicons-admin-site', 6 );
  5. }
  6. add_action( 'admin_menu', 'register_my_custom_menu_page' );
  7.  
  8. Change the Excerpt Length
  9.  
  10. function excerpt_length_example( $words ) {
  11.  return 15;
  12. }
  13. add_filter( 'excerpt_length', 'excerpt_length_example' );
  14.  
  15. Hook into Post Publishing
  16.  
  17. function publish_post_tweet($post_ID) {
  18.   global $post;
  19.   // Code to send a tweet with post info
  20. }
  21. add_action('publish_post', 'publish_post_tweet');
  22.  
  23. Hook Into Widget Initialization
  24.  
  25. function create_my_widget() {
  26.  register_sidebar(array(
  27.  'name' => __( 'My Sidebar', 'mytheme' ),
  28.  'id' => 'my_sidebar',
  29.  'description' => __( 'The one and only', 'mytheme' ),
  30.  ));
  31. }
  32. add_action( 'widgets_init', 'create_my_widget' );
  33.  
  34. Hook Into Front-end Scripts and Styles
  35.  
  36. function theme_styles() {
  37.  wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/css/bootstrap.min.css' );
  38.  wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );
  39.  wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '', true );
  40.  wp_enqueue_script( 'theme_js', get_template_directory_uri() . '/js/theme.js', array('jquery', 'bootstrap_js'), '', true );
  41. }
  42. add_action( 'wp_enqueue_scripts', 'theme_styles' );
Advertisement
Add Comment
Please, Sign In to add comment