Codex Topic: WordPress

  • Get WordPress header-menu named Menu and create as a shortcode

    you can use this menu shortcode in pages, builders anywhere you want in WordPress.   shortcode [header_menu] function header_menu_shortcode($atts) { // Define attributes and their defaults $atts = shortcode_atts( array ( ‘menu’ => ‘header-menu’, ‘container’ => ‘div’, ), $atts, ‘header_menu’ ); // This adds the custom CSS class to the menu $atts[‘menu_class’] = ‘custom_header_menu’; $menu…

  • Calculate all WordPress Posts How Many Words there are

    add this to your functions.php and it will add Word Count named page to the dashboard and it will show the total word count for all posts.   // Add a custom page to the WordPress admin menu function word_count_admin_menu() { add_menu_page( ‘Word Count’, ‘Word Count’, ‘manage_options’, ‘word-count’, ‘word_count_admin_page’, ‘dashicons-editor-spellcheck’, 20 ); } add_action(‘admin_menu’, ‘word_count_admin_menu’);…

  • WordPress Built in SEO Keyword, Meta Desc Fields, No Plugin SEO

    add this to your functions.php and you will have keywords and meta description fields in your posts and pages and post types. this fields will render in <head> if they filled. If you have very minimalistic website and don’t want SEO plugin here is your code have fun with it.     /** * Add…

  • WordPress Built in SEO Sitemap.xml, No Plugin Sitemap.xml

      add this code to the functions.php and you will have sitemap.xml up and running. it is not very advance like pagination or splitting so if the site is bigger than 3k page/post I don’t recommend this method. 🙂       function generate_sitemap() { $output = ‘<?xml version=”1.0″ encoding=”UTF-8″?>’ . “\n”; $output .= ‘<urlset…

  • add custom taxonomy to the custom post type single body class

    add this to the functions.php edit it to your needs // Add Taxonomy to Post Type function my_custom_taxonomy() { register_taxonomy( ‘status’, ‘post_type_name_single’, array( ‘label’ => ‘status’, ‘rewrite’ => array( ‘slug’ => ‘status’ ), ‘hierarchical’ => true, ) ); } add_action( ‘init’, ‘my_custom_taxonomy’ ); // Add Taxonomy to Body Class function my_body_classes( $classes ) { global…

  • Writing a Custom Block for Block Editor

    Example of how we can write a custom block for the block editor.   In this example, there is a gallery block added. By using this block you can add multiple images in the same block. There is CSS issues because I didn’t care how it looks. Didn’t have a chance to use this on…

  • Adding Custom Column to the Admin Posts List View

    Read custom field if there is any show it on the posts list view as new column on this example the code creates a day column and shows the day as a date calculating publish date between the custom field date. This code adds a new column called “Ads Unpublish Day” to the posts list…

  • Custom WordPress Rest Endpoint with custom query loop

    add this code to your functions.php and edit it to your needs on this example I am getting results from “post” posttype and getting results for id, title, thumbnail, content, homepage named custom field and file-upload custom field you can remove, add or edit to your needs this fields.   // https://yourwebsite.org/wp-json/custom/v1/field add_action( ‘rest_api_init’, function…

  • Shortcode Custom Post Type WP Query OWL Ready, Elementor or Bricks Compatible

    add this to your functions.php the shortcode is [get_last_posts] is it anywhere you want, even with builders… you can change the post type post per page or add more properties check this source for more parameters: WP_Query | Class | WordPress Developer Resources   function get_the_last_posts( ) { $qquery = new WP_Query(array( ‘post_type’ => ‘news’,…

  • Adding Custom Query Loop as Shortcode Post Types Taxonomies and more

    Sometimes some themes and some builders makes the building custom query loops harder. For that reason I wrote this simple code and added t other themes functions.php This is a very simple example it is possible make this much much more advance. Check the WP docs examples -> WP_Query | Class | WordPress Developer Resources…