Using Variable Values In Wordpress
#1
Posted 19 July 2011 - 10:00 AM
For example, I want to put my client's social media links in them, so that when the client wants to edit those links she doesn't have to go look into the code and can simply go to a Setting page and update those links (or phone number or any other such information)
#2
Posted 19 July 2011 - 10:45 AM
#3
Posted 19 July 2011 - 01:55 PM
#4
Posted 20 July 2011 - 05:10 PM
#5
Posted 20 July 2011 - 05:13 PM
#6
Posted 20 July 2011 - 05:30 PM
#7
Posted 23 July 2011 - 02:14 PM
Its not just social links. There are a bunch of information that i'd like to use variables for instead of hard coding it (or sometimes hard typing it in a post).
I ended up using a plugin for search and replace. not exactly what i was looking for but gets the job done
#8
Posted 23 July 2011 - 04:52 PM
#9
Posted 23 July 2011 - 09:07 PM
http://codex.wordpre...g/Custom_Fields
http://www.wpbeginne...icks-and-hacks/
#10
Posted 24 July 2011 - 10:07 AM
if ( !function_exists('get_custom_field') ) {
function get_custom_field($field) {
global $post;
$custom_field = get_post_meta($post->ID, $field, true);
echo $custom_field;
}
}
Usage:
<?php get_custom_field('some-custom-field'); ?>
If you want to be able to use it within the content of the post, you could register it as a shortcode:
function custom_field_shortcode($atts) {
extract(shortcode_atts(array(
'field' => 'default-custom-field'
), $atts));
return get_custom_field('field');
}
add_shortcode('my_custom_field','custom_field_shortcode');
Usage (in a post or page):
[my_custom_field field='some-custom-field']
#11
Posted 24 July 2011 - 04:26 PM
Thats exactly what i was looking for. I guess i was (am) too dumb to write that code myself. I appreciate your help.
What file would I put the function itself? Also, when I use the "In Post" code would it work when switching back and forth between HTML and Visual mode in Wordpress? I've seen some codes that work in HTML but as soon as switched to Visual mode they get all funky or not work.
#12
Posted 25 July 2011 - 12:36 PM
And yes, those shortcodes should be just fine regardless of mode. Visual mode messes up HTML, and can mess up some non-standard shortcodes (shortcodes not using the WordPress shortcode engine), but this would be fine.
#13
Posted 31 July 2011 - 01:26 AM
Custom fields are for per-post items.
You probably want to add something to the options table.
I'm afraid its going to take come coding - you are probably better trying to find an existing plugin that suits. Try searching for one of the actual social media service name plus wordpress plugin.
If you want to try the custom route, this might be a starting point for you:
http://codex.wordpre...g_Options_Pages
#14
Posted 28 August 2011 - 01:55 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users






