Edit default read more text in WordPress - php

I would like to customize the read-more link on my WordPress theme, however I would like it to be able to get the attributes sent in the read more tag.
So the <--more--> tag would return the default
While <--more Some Attribute --> would return Some Attribute.
I'm aware that I can edit the read more text with what's below. I just can't figure out how to get the attributes or vars that are passed to the more short-code. If I could figure this out I could simply check if it exists and if not then place in the default text.
function modify_read_more_link() {
return '<div class="read-more"><a class="more-link button" href="' . get_permalink() . '">Custom Read More Link Text</a></div>';
}

what customization you are trying to do ? what about changing the class or using that class use jquery and customize the div !!!
WordPress makes this technique easy, and customizable.
https://codex.wordpress.org/Customizing_the_Read_More

I found the answer to my problem.
Inside my function.php file I needed
function wrap_readmore($more_link) {
//Check if link contains default (more...), if it does replace with Read More
if (preg_match('(more…)', $more_link)) {
$more_link = str_replace('(more…)', 'Read More', $more_link);
}
return '<div class="small-12 columns text-center">' . $more_link . '</div>';
}
add_filter('the_content_more_link', 'wrap_readmore');

Related

Adding content with hooks

I have a beginner question: I want to add a product search form to a WordPress theme via a hook. I want to wrap the product search in a div in order to be able to style it. How can I add the div to the following:
add_action('after_main', my_custom_function');
my_custom_funtion() {
get_product_search_form;
}
Thanks for your help.
It's pretty simple:
add_action('after_main', 'my_custom_function');
function my_custom_function() {
echo '<div class="product-search">' . get_product_search_form( FALSE ) . '</div>';
}
Then, anywhere there is a do_action( 'after_main' ) in your code, this will echo out the search form wrapped in the div. You can change the class, I just added that for the example.
Edit: passed FALSE to the function. get_product_search_form() echoes by default. Passing FALSE returns it instead.
Second edit: You can also use the filter get_product_search_form like this:
add_filter( 'get_product_search_form', function( $form ) {
return '<div class="product-search">' . $form . '</div>';
});

Disable custom post type links depending on the taxonomy option

I have a list (shown as a grid by this plugin) of Custom Post Types, but I need the ones under one taxonomy value to have a link to the inner page.
Example: I have the taxonomy "example" with 3 options (OptionA
- OptionB
- OptionC), but I just want the ones under "OptionB" to have an inner link:
I know there is a solution via css (hiding the links styles), but I would like to keep the whole site clean of css tricks.
Is there any way to achieve this functionality using PHP?
Here is the part of the PHP code that adds the link to the titles:
$output .= '<div class="pl-detailcnt">
<h4 class="pl-title left-txt">';
if (isset($this->pw_hide_date) && ($this->pw_hide_date=='off')){
$output .= '<span class="pl-date">'. get_the_date($this->pw_date_format).'</span>';
}
$output .= ''. get_the_title().'</h4>
</div>';
Since I can't add the whole code (max characters exceeded) as #Dontfeedthecode suggested, here it goes: http://ideone.com/HeVfny
You can query for taxonomies for the post then check to see if your custom post type is in the array it returns:
$post_types = get_object_taxonomies( $post );
if( in_array( 'your taxonomy name', $post_types )) {
// Show link
}
SOLUTION (using a bit of JQuery).
First step:
Add the term-slug as a CSS class, so I can distinguish between classes for customize it later with JQuery.
<div class="add_your_random_class_here '.$term->slug.'">
Second Step:
Disable the links that have the term-slug class created.
<script>
jQuery(function() {
jQuery('.here-goes-your-new-based-slug-class').click(function(e){e.preventDefault();});
});
</script>
Any improvement will be welcome

PHP: Wordpress shortcode with image

I have a problem with a shortcode.
Check this theme out:
http://themeforest.net/item/elogix-responsive-business-wordpress-theme/full_screen_preview/1958520
Please navigate to "Shortcodes-> Toggle" and see the example.
I want to use the toogle function, however, i want to be able to use an image beside the title, like a symbol.
However, when i do this within wordpress, the title will not be shown, and the shortcode gets messed up.
The core code looks like this:
function minti_toggle( $atts, $content = null)
{
extract(shortcode_atts(array(
'title' => '',
), $atts));
return '<div class="toggle"><div class="title">'.$title.'<span></span></div><div class="inner"><div>'. do_shortcode($content) . '</div></div></div>';
}
add_shortcode('toggle', 'minti_toggle');
I am still new at PHP, so I cannot seem to see, where it limits me to only use letters within the title tag, and not an image file as well.
Best Regards
Patrick
Okay, so i figured out the problem, if anyone else needs this:
The problem was, when adding a tag, it would disrupt the title tag, and not display anything.
So i edited the code, so i could input another value, which would then be showed left to the title:
function minti_toggle($atts, $content = null)
{
extract(shortcode_atts(array(
'title' => '',
'image' => ''
), $atts));
return '<div class="toggle"><div class="title">'.$title.'<span style="float:left;margin-right:5%"><img width="22" height="22" src="'.$image.'" class="alignnone wp-image-157"></span></div><div class="inner"><div>'. do_shortcode($content) . '</div></div></div>';
}
add_shortcode('toggle', 'minti_toggle');
This code returns the code input for image. So the shortcode would be
If you want to be able to edit the code in a css file instead, just delete the style in the , and make a class for this in the style.css.
Hope this helps someone :)
For Setting background image in title.
Please make change in .css file of plugins.
.title{
background:url('imageurl');
background-repeat: no-repeat;
}

Savings settings in a custom PHP plugin for WordPress

First, I'd like to pre-emptively apologize for doing anything naive or foolish. I'm a novice programmer, but I'm trying to learn. Right now, I'm trying to develop a plugin for wordpress as part of my internship. The plugin does what it needs to do for the most part, but I just can't seem to make the settings page work the way I want. I know the initialization part of the plugin is working properly, but I'm having trouble with using the settings page. Specifically, I don't where or how to use _POST in order to save the information. I also don't where to place the update_option function call after I've received the information from the settings page. Here's my code right now:
add_action( 'admin_menu', 'menu' );
add_action( 'admin_init', 'plugin_admin_init' );
function plugin_admin_init() { // whitelist options
register_setting( 'plugin_options', 'plugin_options', 'plugin_options_validate' );
add_settings_section('plugin_main', 'Main Settings', 'plugin_section_text', 'plugin');
add_settings_field('plugin_text_string', 'REE View Count Settings', 'plugin_setting_string', 'plugin', 'plugin_main');
}
function menu() {
add_options_page( 'REE View Count Options', 'REE View Count', 'manage_options', 'plugin', 'plugin_options_page' );
}
// generates the settings web page
function plugin_options_page() {
echo '<div class="wrap">';
echo '<h2>Options</h2>';
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">';
// In the line above, I don't know what to put. The file name of the plugin?
// The URL of the settings page on the admin page? Or what I have currently?
// Both the first and last options bring up a 404 page.
settings_fields('plugin_options');
do_settings_sections('plugin');
echo '<input name="Submit" type="submit" value="' . esc_attr_e('Save Changes') . '" />';
echo '</form>';
//update_option('plugin_options', $_POST['plugin_options']);
// Where should I try to update the option? And how?
echo '</div>';
}
//from add_settings_section parameter 3, in plugin_admin_init
function plugin_section_text() {
echo '<p>Main description of this section here.</p>';
}
//Function from 3 paramter of add_settings_field in plugin_admin_init that outputs input HTML
function plugin_setting_string() {
$options = get_option('plugin_options');
echo 'value of options is: ' . $options;
echo "<input id='plugin_text_string' name='plugin_options' size='40' type='text'
value='{$options}' />";
}
//Validation function from register_setting in plugin_admin_init
function plugin_options_validate($input) {
echo "this is input: " . $input;
$newinput = trim($input);
if(!preg_match('/^[0-9]+$/', $newinput)) {
$newinput = 10;
}
update_option('plugin_options', $newinput);
return $newinput;
}
Note: I don't actually use these exact function/variable names - I have them prefixed with the actual plugin name.
Can you help me? I want to take the information the admin inputs into the settings page and update the database with the that information (which in this case is just a single number). I understand that I need to use PHP _POST, but I don't know how. Furthermore, I don't where to post to, because when I use action="the_file_name.php," I get a 404 error upon submission. What should the action of the form be so that I can use the information that I got from the admin submission and use it for later? And after I do that, how do update the setting? And by how, I mean where do I place update_option? I apologize if this seems rambly or vague - I feel like I'm somewhat over my head.
If it helps, I've been building this settings page in the same file as the plugin itself, with the help of this guide: http://ottopress.com/2009/wordpress-settings-api-tutorial/
Unfortunately, I don't see anything in that guide that speaks of updating information, just creating the page itself.
You want to point to action="options.php". It handles updating the values. Check out the following links to get more detailed info.
http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/
http://www.sitepoint.com/wordpress-options-panel/

Using HTML within Wordpress' Category name field

I need to add HTML to the Category names within my Wordpress theme, so that I can define the name as an icon (via the Twitter bootstrap).
Example code as follows:
<a href="link">
<i class="icon-briefcase"></i>
</a>
This would present the Category name as a linked icon.
Is there any way to do this. I've searched endlessly and the only Wordpress plugins I can find allow HTML to be added to the Category description only.
Thanks in advance.
I think what you're trying to do you can easily solve like this:
<?php
foreach((get_the_category()) as $category) {
echo '<a href="link">';
echo '<i class="icon-briefcase">' . $category->cat_name . '</i>';
echo '</a>';
}
?>
This will make all the category names appear like linked icons, like you said. If you want each name to have a different icon you can of course add a conditional statement to render different HTML based on the category name or ID.
EDIT:
Because you want to use the Twitter Bootstrap, you need to assign css classes to the links in order to the display the icon. There are two ways you can do this. One of 'em being that you could name your categories the same as the icons. For example, a category named 'briefcase', would render a link with the class 'icon-briefcase'. The code:
<?php
// Iterate through the available categories
foreach((get_the_category()) as $category) {
echo '<a href="link">'; // Display a link
echo '<i class="icon-' . $category->cat_name . '">' . $category->cat_name . '</i>'; // Create the <li>
echo '</a>';
}
?>
The second way, and I think a bit better for content purposes (more freedom for choice of cat names), would be to use a conditional statement in the code to assign icons to certain categories. For example:
<?php
// Iterate through the available categories
foreach((get_the_category()) as $category) {
// First define a default css name class to use
$iconclass = 'icon-default';
// Then using an if statement, assign a new css class name to the variable based on the name of the category
if($category->cat_name == 'Travel') { $iconclass = 'icon-briefcase'; }
echo '<a href="link">'; // Display a link
echo '<i class="'. $iconclass . '">' . $category->cat_name . '</i>'; // Create the <li>
echo '</a>';
}
?>
I hope this is clear enough.
I think what you want is just the Category Icons plugin.
I just had a similar kind of requirement to add a big capital letter at the beginning on some category names, (but not others) in the same list. The easiest way I found of doing this was using CSS. This is what I ended up doing
#projects-term-4 h5 a:before {
content:'H';
font-size:80px;
display:block;
margin-bottom:10px;
color:white;
}
#projects-term-5 h5 a:before {
content:'S';
font-size:80px;
display:block;
margin-bottom:10px;
color:white;
}
... etc
You could probably impliment a very simple workaround using this method without knowing any php coding or installing any extra plugins. you'll just need to inspect the html code of the generated page to get the class names and id's you need.

Categories