0

Hi i need help in creating shortcode or adding shortcode, as am not a wordpress developer but just i would create my own websites on wordpress by using themes as i find it pretty easy way to do so, now i am in a situation where as i need to create some 100+ pages targeting different cities of my country for eg. ms excel training in Bangalore, ms excel in pune so on, so as its pain full to create all 100 pages individually so i have maintained a master template so i just need to create a pge and then the page design & content is added with the help of master template with shortcode as mentioned below

Title: MS Excel Training in Pune Site Description: %%title%%, training provided by industry experts. The best %%title%% to get trained on MS Excel, Content: [sc name="title"] Get our industry-leading MS Excel experience wherever you access the Internet.

MS Excel Online LIVE Training, [sc name="title"] hosted by us gives you an effective and proven online learning option with an extensive learning catalog and the freedom to attend virtually from anywhere.

Above part works fine with shortcode as it draws the title from page/post title, i have grouped some of my important keywords like Best MS Excel training institute in pune. Best MS Excel training institute in bangalore, so here instead of mentioning the city name can any one let me know how to create shortcode to add city name just after MS Best MS Excel training institute in ------, so that the shortcode can draw the last word of the same page/post for eg. if page title is MS Excel training in mumbai so that the keyword would be Best MS Excel training institute in Mumbai

Awaiting for your reply.......

2

To create a custom shortcode, use wp's add_shortcode(). The simplest place to add it is your theme functions.php, but the preferred way would be to add it to a child theme. The first parameter is your shortcode's name. The second is the function the shortcode will use to generate the inserted content. Writing the function for getting the last word of a the title is also fairly straight-forward:

// Add the Shortcode
add_shortcode( 'last_title_word', 'wpse_get_last_word_in_title' );

/**
 * Function to return the last word of the current post or page title.
 */
function wpse_get_last_word_in_title() {
    $title = get_the_title(); // ask WP for the current post/page title
    $all_title_words = explode( ' ', $title ); // separate all the words into an array
    return array_pop( $all_title_words ); // return the last word.
}

Now you should be able to use "...LIVE Training, [last_title_word] hosted by us..." in your content.

  • Hi Caspar thanks a lot, as u made my day, your piece of code really worked in great way for me. Thanks a lot – Raghu M Jun 11 '18 at 11:09
  • @Raghu M You're very welcome. Perhaps, then, you could please mark this as the accepted answer. Thanks. – Caspar Jun 11 '18 at 14:52
  • Hi Casper how do i mark it as accepted answer. – Raghu M Jun 12 '18 at 9:21
  • Hi Casper could u plz help me in creating mass pages or posts with default content maintained as template as am using wpbakery visual composer to design my wp site and i have installed quick post creator to add multiple pages in one go, as i have maintained a template in wpbakery visual composer and when i try to add multiple pages with the help of quick post creator then its just creates pages but that ll not have any content so i need to open manually each and every page then select the template for content and then need to save so the particular page gets content. – Raghu M Jun 12 '18 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.