How to add a dynamic footer in Wordpress?

Asked

Viewed 634 times

2

I’m making a site in Wordpress and wanted to know if there are any plugin that makes a footer run, and I can change the content of the footer in the backoffice.

I don’t have code because I don’t know how to do it. I wish I had backoffice an option that is a footer and then I can change the content and then in the code I just have to call this one plugin.

  • What if there is no plugin? You can detail this better "I can change the content of the footer in the backoffice"?

  • if there is no plugin I have to do a

  • I wanted to have in the backoffice an option that is footer and then I can change the content and then in the code I just have to call this plugin..

  • you could use a slider as a footer dude, what do you think? if you agree I create an answer;

1 answer

0

If you want to make an option on backend within the Settings area, you must use the Settings API. To do within the settings of the Theme you have to use the Theme Customization API. Each of them has functions to be called on frontend and pull the values.

Another easy way is to create one Custom Post Type where you can register more than one footer option and pull on the frontend with the function get_posts().

In this example plugin, I am creating a post type that only supports titles, see supports => array(SUAS-OPÇÕES):

<?php
/*
 * Plugin Name: Rodapés personalizados
 * Plugin URI: /a/98553/201
 * Version: 1.0
 * Author: brasofilo
 */

add_action( 'init', 'footers_custom_init' );

# Ajustar $labels e $args conforme suas necessidades
function footers_custom_init() {
  $labels = array(
    'name' => 'Footers',
    'singular_name' => 'Footer',
    'add_new' => 'Add New',
    'add_new_item' => 'Add New Footer',
    'edit_item' => 'Edit Footer',
    'new_item' => 'New Footer',
    'all_items' => 'All Footers',
    'view_item' => 'View Footer',
    'search_items' => 'Search Footers',
    'not_found' =>  'No teasers found',
    'not_found_in_trash' => 'No teasers found in Trash', 
    'parent_item_colon' => 'Parent Page',
    'menu_name' => 'Footers'
  );

  $args = array(
    'labels' => $labels,
    'description' => '',
    'public' => false,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => array(),
    'capability_type' => 'page',
    'has_archive' => false, 
    'hierarchical' => true,
    'menu_position' => 60,
    'supports' => array( 'title')
  ); 

  register_post_type( 'footers', $args );
}

if ( ! function_exists( 'imprime_rodape' ) ) {
    # Ajustar $args conforme suas necessidades
    function imprime_rodape() {
        $args = array( 'numberposts' => 1, 'orderby' => 'rand', 'post_type' => 'footers' );
        $rand_footer = get_posts( $args );        
        echo $rand_footer[0]->post_title;
    }
}

Then in the file footer.php of your Theme, use the following plugin function to print a random footer:

<?php if ( function_exists( 'imprime_rodape' ) ) imprime_rodape(); ?>
  • gives for always the last added footer...this is for a betting site

Browser other questions tagged

You are not signed in. Login or sign up in order to post.