Any ideas how to dynamically automate breadcrumbs to the home page in a custom wordpress theme?

Things I need to accomplish:

  1. Establish a "site variable" where we can set what category a blog belongs in. These categories are Option 1, Option 2, Option 3, and Option 4.
  2. When one of the categories is selected, it generates the breadcrumb on the blog’s home page and also the first half of the secondary breadcrumbs in archive or single pages.
  3. Make it so the blog home is automatically the second part of the breadcrumb link path.

Here are the screenshots that show the custom option called Site Information:

enter image description here

enter image description here

enter image description here

enter image description here

Writes to the wp_options database table
enter image description here

Here is the code so far:

class MySettingsPage
{
private $options;

function __construct()
{
    add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
    add_action( 'admin_init', array( $this, 'page_init' ) );
}

function add_plugin_page()
{
    // This page will be under "Settings"
    add_options_page(
        'Settings Admin', 
        'Site Information', 
        'manage_options', 
        'my-setting-admin', 
        array( $this, 'create_admin_page' )
    );
}

function create_admin_page()
{
    // Set class property
    $this->options = get_option( 'site_information_options' );
    ?>
    <div class="wrap">
        <h1>Site Information</h1>
        <form method="post" action="options.php">
        <?php
            // This prints out all hidden setting fields
            settings_fields( 'site-information_group' );
            do_settings_sections( 'my-setting-admin' );
            submit_button();
        ?>
        </form>
    </div>
     <?php
}

function page_init()
{        
    register_setting(
        'site-information_group', 
        'site_information_options', 
        array( $this, 'sanitize' ) 
    );

    add_settings_section(
        'setting_section_id', 
        'Custom Settings', 
        array( $this, 'print_section_info' ), 
        'my-setting-admin' 
    );  

    add_settings_field(
        'parent_category', 
        'Parent Category', 
        array( $this, 'parent_category_callback' ), 
        'my-setting-admin', 
        'setting_section_id'
    );      

    add_settings_field(
        'subcategory', 
        'Subcategory', 
        array( $this, 'subcategory_callback' ), 
        'my-setting-admin', 
        'setting_section_id'
    ); 
        
    add_settings_field(
        'blog_owner_email', 
        'Blog Owner Email', 
        array( $this, 'blog_owner_email_callback' ), 
        'my-setting-admin', 
        'setting_section_id'
    ); 
}

function sanitize( $input )
{
    $new_input = array();
    if( isset( $input['parent_category'] ) )
        $new_input['parent_category'] = sanitize_text_field( $input['parent_category'] );

    if( isset( $input['subcategory'] ) )
        $new_input['subcategory'] = sanitize_text_field( $input['subcategory'] );

    if( isset( $input['blog_owner_email'] ) )
        $new_input['blog_owner_email'] = sanitize_text_field( $input['blog_owner_email'] );

    return $new_input;
}

function print_section_info()
{
    print 'Enter your settings below:';
}

function parent_category_callback()
{
    printf(
        '<select id="parent_category" name="site_information_options[parent_category]" value="%s" >
            <option>Select...</option>  
            <option>Option 1</option>
            <option>Option 2</option>
            <option>Option 3</option>
            <option>Option 4</option>
        </select>',
        isset( $this->options['parent_category'] ) ? esc_attr( $this->options['parent_category']) : ''
    );
}

function subcategory_callback()
{
    printf(
        '<select id="subcategory" name="site_information_options[subcategory]" value="%s" >
            <option>Select...</option>
            <option>Option 1</option>
            <option>Option 2</option>
        </select>',
        isset( $this->options['subcategory'] ) ? esc_attr( $this->options['subcategory']) : ''
    );
}

function blog_owner_email_callback()
{
    printf(
        '<input type="text" id="blog_owner_email" name="site_information_options[blog_owner_email]" value="%s" />',
         isset( $this->options['blog_owner_email'] ) ? esc_attr( $this->options['blog_owner_email']) : ''
    );
}
}
if( is_admin())
    $my_settings_page = new MySettingsPage(); 

$299 Affordable Web Design WordPress

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Any ideas how to dynamically automate breadcrumbs to the home page in a custom wordpress theme?

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.