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(); ?>
What if there is no plugin? You can detail this better "I can change the content of the footer in the backoffice"?
– brasofilo
if there is no plugin I have to do a
– usersantos
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..
– usersantos
you could use a slider as a footer dude, what do you think? if you agree I create an answer;
– Paulo Roberto Rosa