Looking at the file in my editor it's a function and inside the function is a string in single quotes.
I have this wordpress function like so:
<div class="site-info">
<?php do_action( 'focus_credits' ); ?>
</div><!-- .site-info -->
When i inspect element in chrome it's like this:
<div class="site-info">
Theme By yada yada yada and a link to their website here </div>
My question is how is the literal string 'focus credits' returning the name of the theme and an href link to their website.
I've discovered the do_action function in the plugin.php
function do_action($tag, $arg = '') {
global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
if ( ! isset($wp_actions[$tag]) )
$wp_actions[$tag] = 1;
else
++$wp_actions[$tag];
// Do 'all' actions first
if ( isset($wp_filter['all']) ) {
$wp_current_filter[] = $tag;
$all_args = func_get_args();
_wp_call_all_hook($all_args);
}
if ( !isset($wp_filter[$tag]) ) {
if ( isset($wp_filter['all']) )
array_pop($wp_current_filter);
return;
}
if ( !isset($wp_filter['all']) )
$wp_current_filter[] = $tag;
$args = array();
if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this)
$args[] =& $arg[0];
else
$args[] = $arg;
for ( $a = 2; $a < func_num_args(); $a++ )
$args[] = func_get_arg($a);
// Sort
if ( !isset( $merged_filters[ $tag ] ) ) {
ksort($wp_filter[$tag]);
$merged_filters[ $tag ] = true;
}
reset( $wp_filter[ $tag ] );
do {
foreach ( (array) current($wp_filter[$tag]) as $the_ )
if ( !is_null($the_['function']) )
call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
} while ( next($wp_filter[$tag]) !== false );
array_pop($wp_current_filter);
}
so his 'focus_credits' calling some text from the DB?
I looked through some of the tables but couldn't find anything relating..
Any help where to look would be great. Thanks in advance.
do_action() inserts an action hook in your template. If you dig through your theme's files, possibly functions.php, you should find a function that is hooked to this action hook:
add_action( 'focus_credits', 'focus_credits' );
function focus_credits(){
echo 'Theme By yada yada yada and a link to their website here';
}
More info on do_action(): http://codex.wordpress.org/Function_Reference/do_action
Related
I used this code to show responsive ad from adsense after 5th paragraph.
Adding Ads After First And Second Paragraph of WordPress Post
This is the code I use on my site:
function prefix_insert_after_paragraph2( $ads, $content ) {
if ( ! is_array( $ads ) ) {
return $content;
}
$closing_p = '</p>';
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}
$n = $index + 1;
if ( isset( $ads[ $n ] ) ) {
$paragraphs[$index] .= $ads[ $n ];
}
}
return implode( '', $paragraphs );
}
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
if ( is_single() && ! is_admin() ) {
$content = prefix_insert_after_paragraph2( array(
// The format is: '{PARAGRAPH_NUMBER}' => 'AD_CODE',
'5' => '<div>Ad code after FIRST paragraph goes here</div>',
), $content );
}
return $content;
}
I would like to exclude this code only for specific posts. How can I add the proper code to be able to exclude this function for post id=280?
Thank you.
Why do you want to exclude this function inside functions.php?
I think it's much easier to do it inside the post loop.
For example, to exclude the POST ID 280, if you're inside the page.php, or similar you can do this:
global $post;
if ($post->ID == 280){ remove_filter( 'the_content', 'prefix_insert_post_ads' ); }
This way you have the 'add_filter' on your functions.php file, and if you find the exception inside the post (ID=280), you remove the filter.
Just U have to check the current post_id. E.g. :
function prefix_insert_post_ads( $content ) {
global $post;
$post_id = $post->ID;
$post_ids_excluded = [280,....]; // excluded posts ids
if ( in_array($post_id,$post_ids_excluded) ){
return $content;
}
/*
... the same code .....
*/
}
I am using MediaWiki in combination with Joomla. As I want to add icons to some links I need to connect both. I know that this is possible through putting the img tag inside the a tag.
BUT the problem is that some links are generated throgh a function called makeListItem that MediaWiki uses for more than just these links. Now my question is, can I somehow connect the img to the a without putting it inside the a tag?
This calls the function to create the elements:
<?php $this->renderNavigation( 'PERSONAL' ); ?>
The actual function (shortened):
foreach ( $personalTools as $key => $item ) {
?>
<div class="searchbox" style="clear:both;">
<img src="<?php echo $icon[$key] ?>" alt="p-Icons" class="iconnav"/>
<?php
echo $this->makeListItem( $key, $item );
?>
</div>
<?php
}
?>
The src of the image is defined in a array that is declared just above the foreach.
Thanks in advance
You have to modify your makeListItem() function (BaseTemplate class).
function makeListItem( $key, $item, $options = array() ) {
if ( isset( $item['links'] ) ) {
$links = array();
foreach ( $item['links'] as $linkKey => $link ) {
$links[] = $this->makeLink( $linkKey, $link, $options );
}
$html = implode( ' ', $links );
} else {
$link = $item;
// These keys are used by makeListItem and shouldn't be passed on to the link
foreach ( array( 'id', 'class', 'active', 'tag', 'itemtitle' ) as $k ) {
unset( $link[$k] );
}
if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
// The id goes on the <li> not on the <a> for single links
// but makeSidebarLink still needs to know what id to use when
// generating tooltips and accesskeys.
$link['single-id'] = $item['id'];
}
$html = $this->makeLink( $key, $link, $options );
}
$attrs = array();
foreach ( array( 'id', 'class' ) as $attr ) {
if ( isset( $item[$attr] ) ) {
$attrs[$attr] = $item[$attr];
}
}
if ( isset( $item['active'] ) && $item['active'] ) {
if ( !isset( $attrs['class'] ) ) {
$attrs['class'] = '';
}
$attrs['class'] .= ' active';
$attrs['class'] = trim( $attrs['class'] );
}
if ( isset( $item['itemtitle'] ) ) {
$attrs['title'] = $item['itemtitle'];
}
return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
}
i have a problem with my WP function. I need it to ONLY be shown on blog posts. Right now it get shown on the other pages such as the frontpage.
Here is my function in functions.php:
function my_sp_function( $content ) {
$include = FALSE;
$post = FALSE;
if ( in_category( array( 3, 4, 5, 6, 91, 133 ) ) ) {
$include = TRUE;
}
if (get_post_type(get_the_ID()) == 'post'){
$post = TRUE;
}
if ( $post = TRUE AND $include == TRUE ) {
return $content;
}
}
Anybody there knows what i do wrong?
I have tried with this code now, it still shows the $content on the front page..
function my_sp_function( $content ) {
$include = FALSE;
$post = FALSE;
if ( in_category( array( 3, 4, 5, 6, 91, 133 ) ) ) {
$include = TRUE;
}
if( is_home() || is_front_page() ) {
$include = FALSE;
}
if ( $post == TRUE AND $include == TRUE ) {
return $content;
}
}
If you would like to include your function only on the home page you have two options - only insert the function into the single.php template in your theme, or the prefered method is to only hook your function to the_content when is_single() is true but is_page() is false.
function my_sp_function( $content ) {
$content .= "Some more stuff for the_content!";
return $content;
}
if ( is_single() && ! is_page() ){
add_filter( 'the_content', 'my_sp_function' );
}
Here is a simple code which shows the Adsense or any ad code after second paragraph on single post page. But I want to know how to modify it so that it can run a dynamic function.
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div>Ads code goes here</div>';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
}
return $content;
}
// Parent Function that makes the magic happen
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
$closing_p = '</p>';
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}
if ( $paragraph_id == $index + 1 ) {
$paragraphs[$index] .= $insertion;
}
}
return implode( '', $paragraphs );
}
In fact I want to replace
$ad_code = '<div>Ads code goes here</div>';
with
$ad_code = '<?php if(function_exists('echo_ald_crp')) echo_ald_crp(); ?>';
Is there any way to do it??
Well, you can't assign PHP to a string var and expect it to execute. You could create a function with the code in it, have it return something, and then set the variable equal to the function call. Like this:
function output_function() {
//do something here
return $thing_you_want_to_return;
}
function prefix_insert_post_ads( $content ) {
$ad_code = output_function();
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
}
return $content;
}
That way, when the variable is assigned, it'll run your function and return what you want to be echoed out with prefix_insert_after_paragraph().
I am a newbie and have a piece of Wordpress code which has a glitch in it.
Sorry if my question is silly, though the support from where I bought the theme seems to answer with a great delay.
I will paste it and maybe someone can help. If no one can figure out the problem I will delete the question.
The code adds a few changes to the breadcrumb navigation on my site.
The problem I think is with this:
// Add the trail back on to the end.
$links[] = $trail['trail_end'];
// Add the new links, and the original trail's end, back into the trail.
array_splice( $trail, 1, count( $trail ) - 1, $links );
These two line of code should add a <span class="trail-end"></span> to the end of the breadcrumbs around the words "Xpand Xtreme Pump" (in my link example)
Here is the code:
function woo_custom_breadcrumbs_trail_add_product_categories ( $trail ) {
if ( ( get_post_type() == 'product' ) && is_singular() ) {
global $post;
$taxonomy = 'product_cat';
$terms = get_the_terms( $post->ID, $taxonomy );
$links = array();
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $c ) {
$parents = woo_get_term_parents( $c->term_id, $taxonomy, true, ', ', $c->name, array() );
if ( $parents != '' && ! is_wp_error( $parents ) ) {
$parents_arr = explode( ', ', $parents );
foreach ( $parents_arr as $p ) {
if ( $p != '' ) { $links[] = $p; }
}
}
}
// Add the trail back on to the end.
$links[] = $trail['trail_end'];
// Add the new links, and the original trail's end, back into the trail.
array_splice( $trail, 1, count( $trail ) - 1, $links );
}
}
return $trail;
} // End woo_custom_breadcrumbs_trail_add_product_categories()
Try this:
...
// Wrap the trail_end with your span tag
$trail['trail_end'] = '<span class="trail-end">' . end($trail) . '</span>';
// Add the trail back on to the end.
$links[] = $trail['trail_end'];
...
Remember, that this is a hack, I'd recommend doing this in the template rendering the bread-crumbs.