I don't know how to place Get Theme Mod - wordpress

I am developing a wordpress theme and i am trying to add the cutomizer feature.
I want to change to the text only using customizer, otherwise it should be set to default. The section gets added to the customizer but not affecting the text. I wat to change powered by wordpress and other options of footer.
Below is the code i have.
<footer id="ob-footer" class="site-footer" <? echo get_theme_mod('footer');?> >
<div class="site-info" >
<a href="<?php echo esc_url( __( 'https://wordpress.org/', 'openblogger' ) ); ?>">
<?php
/* translators: %s: CMS name, i.e. WordPress. */
printf( esc_html__( 'Proudly powered by %s', 'openblogger' ), 'WordPress' );
?>
</a>
<span class="sep"> | </span>
<?php
/* translators: 1: Theme name, 2: Theme author. */
printf( esc_html__( 'Theme: %1$s by %2$s.', 'openblogger' ), 'openblogger', 'WebsiteGuider' );
?>
</div><!-- .site-info -->
</footer>
I don't know what to do to make it happen. The customizer code looks like:
/**
* Create site footer Setting and customise Control
*/
function your_theme_new_customizer_settings($wp_customize) {
$wp_customize->add_section( 'hellop' , array(
'title' => __( 'Site Footer', 'openblogger' ),
'priority' => 30
) );
// add a setting for the site footer text
$wp_customize->add_setting('footer');
// Add a control to change text
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'footer',
array(
'label' => 'Update Text Here',
'section' => 'hellop',
'settings' => 'footer',
) ) );
}
add_action('customize_register', 'your_theme_new_customizer_settings');

Thank You all of you guys, no one answered and now i solved it of my own

Related

Why some of Wordpress theme doesn't have Header Image Section

I am new in Wordpress. I want to know. Why some of the Wordpress themes don't have header image section in Theme customize? How to add this section to the theme customizer? Is there any way to do it
And one question. How can I modify the upload file image in the theme customizer?
I want to add more field and change the crop size
this depends on the WordPress theme developer how they design and develop themes but you can achieve this by adding your own option like (image, textarea , input) fields in the customizer area.
Here is the example add this code in a function.php file
// Header Logo
function add_logo_customizer($wp_customize) {
$wp_customize->add_section(
'logo_image',
array(
'title' => 'Logo Image',
'priority' => 45,
)
);
$wp_customize->add_setting( 'Logo-upload' );
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
'lp-image_selector',
array(
'label' => 'Logo Image',
'section' => 'logo_image',
'settings' => 'Logo-upload'
)
)
);
}
add_action('customize_register', 'add_logo_customizer');
and you can call it as <?php echo get_theme_mod( 'Logo-upload' ); ?>
The above code is tested and it works
For the first you need to add support to custom-header.
See the codex:
https://developer.wordpress.org/themes/functionality/custom-headers/
Obviously, you need to create a php file with the code and include in the functions.php or add the code directly to your functions.php file.
function themename_custom_header_setup() {
$defaults = array(
// Default Header Image to display
'default-image' => get_template_directory_uri() . '/images/headers/default.jpg',
// Display the header text along with the image
'header-text' => false,
// Header text color default
'default-text-color' => '000',
// Header image width (in pixels)
'width' => 1000,
// Header image height (in pixels)
'height' => 198,
// Header image random rotation default
'random-default' => false,
// Enable upload of image file in admin
'uploads' => false,
// function to be called in theme head section
'wp-head-callback' => 'wphead_cb',
// function to be called in preview page head section
'admin-head-callback' => 'adminhead_cb',
// function to produce preview markup in the admin screen
'admin-preview-callback' => 'adminpreview_cb',
);
}
add_action( 'after_setup_theme', 'themename_custom_header_setup' );
Then on your header.php get the image and put in where you want it.
<?php if ( get_header_image() ) : ?>
<div id="site-header">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<img src="<?php header_image(); ?>" width="<?php echo absint( get_custom_header()->width ); ?>" height="<?php echo absint( get_custom_header()->height ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
</a>
</div>
*functions.php is on the root of your theme folder, if your theme uses a "child-theme" please use this folder to do the changes.
And answering your question, when you upload the image you can crop and resize the image. Wordpress cannot edit photos as an editor, only resize and crop.

Add anchor tag to wordpress site header customization

I have a Wordpress site that needs some fixes and one of my issues is, that I can't add an anchor tag to the Customize page options list. What I mean is the following:
This is my information module that I can change, but for now it accepts only the <strong> tags along with some others that have been added to the array() that it is using. Here is the code that is working for me now, but as you can see, the anchor has been hardcoded into it:
<div class="text">
<a id="mainPhone" href="tel:02086109182">
<?php echo wp_kses( nl2br( $header_phone ), array( 'br' => array(), 'strong' => array(), 'span' => array() ) ); ?>
</a>
</div>
How can I switch from this to something like this:
<div class="text">
<?php echo wp_kses( nl2br( $header_phone ), array( 'br' => array(), 'strong' => array(), 'a' => array(), 'span' => array() ) ); ?>
</div>
I have added 'a' => array() to it, and as it seems it adds an anchor to the content (it gets underlined and etc.) but It is not clickable (my guess is that the href attribute needs to be added in some way?).
How can I do this? Thanks in advance!

Wordpress - Featured image on a custom post archive page

i have created a custom post named Products.
register_post_type( 'products',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'thumbnail' )
);
I have also created a php file named archive-products.php and made it into a template.
In Wordpress I have created a page named Products and selected the products template.
On that static page (that uses the archive template) I have uploaded a image into the Featured Image panel.
In my header I have the code:
echo get_the_post_thumbnail();
But this echos the Featured image of the last custom post in the list (all the products posts have a featured image as well), not the Featured image of the static/archive page, which is what i want. Is this possible to achieve?
Thanks!
I did the very same thing and came across the following answer that solved my problem: https://wordpress.stackexchange.com/a/175228
Save your custom post type archive template as a page.
For example, page-products.php
Backup locally and delete your custom post type archive template from your server.
Show the image with the_post_thumbnail(), put it in a variable with get_the_post_thumbnail(), or make it a background image with your page title over it:
$bg = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'full' );
if( is_page('products') ) : ?>
<div style="background: url('<?php echo $bg[0]; ?>') repeat center center #fbfbfb; background-size:cover;">
<?php the_title( '<h1 class="page-title">', '</h1>' ); ?>
</div>
<?php endif; ?>
Save your permalinks and refresh your page.
This is what worked for me. Hope it helps somebody. :)

How to display a custom menu in Wordpress?

I currently have two different custom menus. I want the first menu "Main" to be displayed at the top of the page as the top navigation. I want the second menu "Slider" under the slider.
I have this at the top:
<?php wp_nav_menu(array('theme_location' => '','container' => '',));?>
And somehow it's picking up the links in the first menu "Main" and showing it on top. Now I want to display the links from the 2nd menu under the slider
<?php register_nav_menu( 'Slider', 'Under Slider Navigation' ); ?>
<?php wp_nav_menu(array('theme_location' => 'Slider','container' => '',));?>
And with this, it is showing every single page I Have in the nav bar. Please help.
try the below function
function register_my_menus() {
register_nav_menus(
array(
'Slider' => __( 'Under Slider Navigation' ),
)
);
}
add_action( 'init', 'register_my_menus' );
<?php wp_nav_menu( array( 'theme_location' => 'Slider' ) ); ?>
register_nav_menus must be in array
Initialise the menu before you register it. Also, ideally this should go into functions.php
<?php function my_second_nav(){
wp_nav_menu(array('theme_location' => 'Slider','container' => '',))}
register_nav_menu( 'Slider', 'Under Slider Navigation' ); ?>
Then position it wherever you want
<?php my_second_nav(); ?>

Adding Menu Support to Custom Wordpress Theme

I am creating my first Wordpress theme and I am struggling with menu support:
I added a custom menu in functions.php and implemented it into my header.php like shown below but the menu-option in the administration area does not show up!
# functions.php
<?php
add_theme_support( 'menus' );
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu' ),
'secondary-menu' => __( 'Secondary Menu' )
)
);
}
?>
# header.php
# [...]
<?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>
# [...]
My Setting:
Wordpress Version 3.4.2
MAMP Development Environment
No plugins
Other information:
The menu option shows up in other templates
The menu is getting rendered correctly on the page
What am I missing here?
Edit #1
I can't even see the menu option in the admin menu (like here!)
Few things - You don't need add_theme_support(); nor the add_action('init', 'register_my_menus')
Just straight up call the register_nav_menus function, like so:
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu' ),
'secondary-menu' => __( 'Secondary Menu' )
)
);
Can also check if the function exists if you desire. But if it's only for use on your own theme and you know it exists it's not really needed.
if ( function_exists( 'register_nav_menus' ) ) {
...
}

Resources